Fakultas Ilmu Komputer UI

Commit 9c5f800b authored by Rayhan Muzakki's avatar Rayhan Muzakki 💬
Browse files

Bugfixing

parent 1ab4924f
# 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,7 +133,6 @@ class Product(db_models.Model):
verbose_name=_('price')
)
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(
decimal_places=2,
default=decimal.Decimal('0'),
......@@ -169,11 +168,6 @@ class Product(db_models.Model):
verbose_name = _('product')
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):
return self.code
......@@ -375,7 +369,6 @@ class TransactionItem(db_models.Model):
validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
verbose_name=_('product price')
)
product_pre_order = db_models.BooleanField(verbose_name=_('product pre-order'))
quantity = db_models.PositiveIntegerField(verbose_name=_('quantity'))
class Meta:
......
......@@ -246,7 +246,6 @@ def create_transaction_report(filter_params): # pylint: disable=too-many-locals
(transaction_item_transaction_transaction_number_with_hyperlink, _('Transaction Number')),
('product_name', _('Product Name')),
('product_price', _('Product Price')),
('product_pre_order', _('Product Pre-Order')),
('quantity', _('Quantity')),
]
write_queryset_data_to_worksheet(
......
......@@ -261,7 +261,6 @@ class ProductSerializer(serializers.ModelSerializer):
'description',
'price',
'stock',
'pre_order',
'modal',
'profit',
'image',
......@@ -270,17 +269,6 @@ class ProductSerializer(serializers.ModelSerializer):
model = models.Product
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):
product = ProductSerializer(read_only=True)
......@@ -318,7 +306,6 @@ class TransactionItemSerializer(serializers.ModelSerializer):
'product_code',
'product_name',
'product_price',
'product_pre_order',
'quantity',
]
model = models.TransactionItem
......@@ -327,7 +314,6 @@ class TransactionItemSerializer(serializers.ModelSerializer):
'product',
'product_name',
'product_price',
'product_pre_order',
'quantity',
]
......
......@@ -71,12 +71,10 @@ def fill_dependent_transaction_item_fields(sender, instance, **_kwargs):
if instance.product is None:
instance.product_name = None
instance.product_price = None
instance.product_pre_order = None
else:
instance.product_name = instance.product.name
instance.product_price = instance.product.price
instance.product_pre_order = instance.product.pre_order
......
......@@ -1168,7 +1168,6 @@ class ProductTest(rest_framework_test.APITestCase):
def test_create_product_success(self):
data = seeds.PRODUCT_DATA
data['pre_order'] = True
data['subcategory']= self.subcategory.id
response = request(
......@@ -1184,7 +1183,7 @@ class ProductTest(rest_framework_test.APITestCase):
def test_create_product_fail(self):
data = dict(seeds.PRODUCT_DATA, subcategory=self.subcategory.id)
data['stock'] = None
data['name'] = None
response = request(
'POST',
'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