Fakultas Ilmu Komputer UI

Commit 97b3dae1 authored by Rayhan Muzakki's avatar Rayhan Muzakki 💬
Browse files

Merge branch 'bugfixing' into 'staging'

Bugfixing

See merge request ppl-fasilkom-ui/itproject-2020/group-b/pilar-backend!103
parents 3748e999 843c25fa
# Generated by Django 3.0.7 on 2020-10-26 09:14 # Generated by Django 3.0.7 on 2020-12-20 09:30
import api.utils import api.utils
from decimal import Decimal
import django.contrib.postgres.fields.citext import django.contrib.postgres.fields.citext
import django.core.validators
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import uuid import uuid
...@@ -14,6 +16,21 @@ class Migration(migrations.Migration): ...@@ -14,6 +16,21 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.AddField(
model_name='product',
name='modal',
field=models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))], verbose_name='modal'),
),
migrations.AddField(
model_name='product',
name='profit',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))], verbose_name='profit'),
),
migrations.AddField(
model_name='product',
name='total_profit',
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0'), max_digits=12, null=True, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))], verbose_name='total profit'),
),
migrations.CreateModel( migrations.CreateModel(
name='ProgramProgress', name='ProgramProgress',
fields=[ fields=[
......
# Generated by Django 3.0.7 on 2020-11-24 12:31
from decimal import Decimal
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0002_programprogress'),
]
operations = [
migrations.AddField(
model_name='product',
name='modal',
field=models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))], verbose_name='modal'),
),
migrations.AddField(
model_name='product',
name='profit',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))], verbose_name='profit'),
),
migrations.AddField(
model_name='product',
name='total_profit',
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0'), max_digits=12, null=True, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))], verbose_name='total profit'),
),
]
# Generated by Django 3.0.7 on 2020-12-18 08:32
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0003_auto_20201124_1931'),
]
operations = [
migrations.RemoveField(
model_name='product',
name='pre_order',
),
migrations.RemoveField(
model_name='transactionitem',
name='product_pre_order',
),
]
...@@ -133,6 +133,7 @@ class Product(db_models.Model): ...@@ -133,6 +133,7 @@ class Product(db_models.Model):
verbose_name=_('price') verbose_name=_('price')
) )
stock = db_models.PositiveIntegerField(blank=True, null=True, verbose_name=_('stock')) stock = db_models.PositiveIntegerField(blank=True, null=True, verbose_name=_('stock'))
pre_order = db_models.BooleanField(default=False, verbose_name=_('pre-order'))
modal = db_models.DecimalField( modal = db_models.DecimalField(
decimal_places=2, decimal_places=2,
default=decimal.Decimal('0'), default=decimal.Decimal('0'),
...@@ -140,6 +141,7 @@ class Product(db_models.Model): ...@@ -140,6 +141,7 @@ class Product(db_models.Model):
validators=[validators.MinValueValidator(decimal.Decimal('0.01'))], validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
verbose_name=_('modal') verbose_name=_('modal')
) )
profit= db_models.DecimalField( profit= db_models.DecimalField(
blank=True, blank=True,
null=True, null=True,
...@@ -168,6 +170,11 @@ class Product(db_models.Model): ...@@ -168,6 +170,11 @@ class Product(db_models.Model):
verbose_name = _('product') verbose_name = _('product')
verbose_name_plural = _('products') verbose_name_plural = _('products')
def save(self, *args, **kwargs): # pylint: disable=arguments-differ
if (self.pre_order) and (self.stock is not None):
self.stock = None
super().save(*args, **kwargs)
def __str__(self): def __str__(self):
return self.code return self.code
...@@ -369,6 +376,7 @@ class TransactionItem(db_models.Model): ...@@ -369,6 +376,7 @@ class TransactionItem(db_models.Model):
validators=[validators.MinValueValidator(decimal.Decimal('0.01'))], validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
verbose_name=_('product price') verbose_name=_('product price')
) )
product_pre_order = db_models.BooleanField(verbose_name=_('product pre-order'))
quantity = db_models.PositiveIntegerField(verbose_name=_('quantity')) quantity = db_models.PositiveIntegerField(verbose_name=_('quantity'))
class Meta: class Meta:
......
...@@ -246,6 +246,7 @@ def create_transaction_report(filter_params): # pylint: disable=too-many-locals ...@@ -246,6 +246,7 @@ def create_transaction_report(filter_params): # pylint: disable=too-many-locals
(transaction_item_transaction_transaction_number_with_hyperlink, _('Transaction Number')), (transaction_item_transaction_transaction_number_with_hyperlink, _('Transaction Number')),
('product_name', _('Product Name')), ('product_name', _('Product Name')),
('product_price', _('Product Price')), ('product_price', _('Product Price')),
('product_pre_order', _('Product Pre-Order')),
('quantity', _('Quantity')), ('quantity', _('Quantity')),
] ]
write_queryset_data_to_worksheet( write_queryset_data_to_worksheet(
......
...@@ -261,6 +261,7 @@ class ProductSerializer(serializers.ModelSerializer): ...@@ -261,6 +261,7 @@ class ProductSerializer(serializers.ModelSerializer):
'description', 'description',
'price', 'price',
'stock', 'stock',
'pre_order',
'modal', 'modal',
'profit', 'profit',
'image', 'image',
...@@ -269,6 +270,17 @@ class ProductSerializer(serializers.ModelSerializer): ...@@ -269,6 +270,17 @@ class ProductSerializer(serializers.ModelSerializer):
model = models.Product model = models.Product
read_only_fields = ['id', 'code'] read_only_fields = ['id', 'code']
def validate(self, attrs):
instance = self.instance
stock = attrs.get('stock', getattr(instance, 'stock', None))
pre_order = attrs.get('pre_order', getattr(instance, 'pre_order', None))
errors = {}
if (stock is None) and (not pre_order):
errors['stock'] = _('Stock cannot be empty if it is not a pre-order.')
if errors:
raise serializers.ValidationError(errors)
return super().validate(attrs)
class CartItemSerializer(serializers.ModelSerializer): class CartItemSerializer(serializers.ModelSerializer):
product = ProductSerializer(read_only=True) product = ProductSerializer(read_only=True)
...@@ -306,6 +318,7 @@ class TransactionItemSerializer(serializers.ModelSerializer): ...@@ -306,6 +318,7 @@ class TransactionItemSerializer(serializers.ModelSerializer):
'product_code', 'product_code',
'product_name', 'product_name',
'product_price', 'product_price',
'product_pre_order',
'quantity', 'quantity',
] ]
model = models.TransactionItem model = models.TransactionItem
...@@ -314,6 +327,7 @@ class TransactionItemSerializer(serializers.ModelSerializer): ...@@ -314,6 +327,7 @@ class TransactionItemSerializer(serializers.ModelSerializer):
'product', 'product',
'product_name', 'product_name',
'product_price', 'product_price',
'product_pre_order',
'quantity', 'quantity',
] ]
......
...@@ -71,10 +71,12 @@ def fill_dependent_transaction_item_fields(sender, instance, **_kwargs): ...@@ -71,10 +71,12 @@ def fill_dependent_transaction_item_fields(sender, instance, **_kwargs):
if instance.product is None: if instance.product is None:
instance.product_name = None instance.product_name = None
instance.product_price = None instance.product_price = None
instance.product_pre_order = None
else: else:
instance.product_name = instance.product.name instance.product_name = instance.product.name
instance.product_price = instance.product.price instance.product_price = instance.product.price
instance.product_pre_order = instance.product.pre_order
......
...@@ -1168,6 +1168,7 @@ class ProductTest(rest_framework_test.APITestCase): ...@@ -1168,6 +1168,7 @@ class ProductTest(rest_framework_test.APITestCase):
def test_create_product_success(self): def test_create_product_success(self):
data = seeds.PRODUCT_DATA data = seeds.PRODUCT_DATA
data['pre_order'] = True
data['subcategory']= self.subcategory.id data['subcategory']= self.subcategory.id
response = request( response = request(
...@@ -1183,7 +1184,7 @@ class ProductTest(rest_framework_test.APITestCase): ...@@ -1183,7 +1184,7 @@ class ProductTest(rest_framework_test.APITestCase):
def test_create_product_fail(self): def test_create_product_fail(self):
data = dict(seeds.PRODUCT_DATA, subcategory=self.subcategory.id) data = dict(seeds.PRODUCT_DATA, subcategory=self.subcategory.id)
data['name'] = None data['stock'] = None
response = request( response = request(
'POST', 'POST',
'product-list', 'product-list',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment