Fakultas Ilmu Komputer UI

Commit 007b06cf authored by Rayhan Muzakki's avatar Rayhan Muzakki 💬
Browse files

Bugfixing

parent 97b3dae1
# Generated by Django 3.0.7 on 2020-12-20 09:30 # Generated by Django 3.0.7 on 2020-12-29 03:28
import api.utils import api.utils
from decimal import Decimal from decimal import Decimal
...@@ -16,6 +16,14 @@ class Migration(migrations.Migration): ...@@ -16,6 +16,14 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RemoveField(
model_name='product',
name='pre_order',
),
migrations.RemoveField(
model_name='transactionitem',
name='product_pre_order',
),
migrations.AddField( migrations.AddField(
model_name='product', model_name='product',
name='modal', name='modal',
......
...@@ -133,7 +133,7 @@ class Product(db_models.Model): ...@@ -133,7 +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'),
...@@ -141,7 +141,6 @@ class Product(db_models.Model): ...@@ -141,7 +141,6 @@ 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,
...@@ -170,11 +169,6 @@ class Product(db_models.Model): ...@@ -170,11 +169,6 @@ 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
...@@ -376,7 +370,7 @@ class TransactionItem(db_models.Model): ...@@ -376,7 +370,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,7 +246,6 @@ def create_transaction_report(filter_params): # pylint: disable=too-many-locals ...@@ -246,7 +246,6 @@ 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(
......
...@@ -99,7 +99,7 @@ SHIPMENT_CONFIG_DATA = { ...@@ -99,7 +99,7 @@ SHIPMENT_CONFIG_DATA = {
BATCH_DATA = { BATCH_DATA = {
'batch_name': 'Batch 1', 'batch_name': 'Batch 1',
'start_date': '2020-12-19', 'start_date': '2020-12-26',
'end_date': '2020-12-25', 'end_date': '2021-01-01',
'shipping_cost': '60000', 'shipping_cost': '60000',
} }
...@@ -261,7 +261,6 @@ class ProductSerializer(serializers.ModelSerializer): ...@@ -261,7 +261,6 @@ class ProductSerializer(serializers.ModelSerializer):
'description', 'description',
'price', 'price',
'stock', 'stock',
'pre_order',
'modal', 'modal',
'profit', 'profit',
'image', 'image',
...@@ -270,16 +269,7 @@ class ProductSerializer(serializers.ModelSerializer): ...@@ -270,16 +269,7 @@ 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):
...@@ -318,7 +308,6 @@ class TransactionItemSerializer(serializers.ModelSerializer): ...@@ -318,7 +308,6 @@ 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
...@@ -327,7 +316,6 @@ class TransactionItemSerializer(serializers.ModelSerializer): ...@@ -327,7 +316,6 @@ class TransactionItemSerializer(serializers.ModelSerializer):
'product', 'product',
'product_name', 'product_name',
'product_price', 'product_price',
'product_pre_order',
'quantity', 'quantity',
] ]
......
...@@ -71,12 +71,10 @@ def fill_dependent_transaction_item_fields(sender, instance, **_kwargs): ...@@ -71,12 +71,10 @@ 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,7 +1168,6 @@ class ProductTest(rest_framework_test.APITestCase): ...@@ -1168,7 +1168,6 @@ 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(
...@@ -1184,7 +1183,7 @@ class ProductTest(rest_framework_test.APITestCase): ...@@ -1184,7 +1183,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['stock'] = None data['name'] = None
response = request( response = request(
'POST', 'POST',
'product-list', 'product-list',
......
...@@ -172,13 +172,6 @@ class CartCheckout(rest_framework_views.APIView): ...@@ -172,13 +172,6 @@ class CartCheckout(rest_framework_views.APIView):
transaction_status = ( transaction_status = (
'001' if serializer.validated_data['payment_method'] == 'TRF' else '002' '001' if serializer.validated_data['payment_method'] == 'TRF' else '002'
) )
batch = (
None if serializer.validated_data['payment_method'] == 'TRF'
else models.Batch.objects.filter(
start_date__lte=timezone.now().date(),
end_date__gte=timezone.now().date()).first()
)
transaction = models.Transaction.objects.create( transaction = models.Transaction.objects.create(
user=user, user=user,
...@@ -667,7 +660,6 @@ class ProductDetail(generics.RetrieveUpdateDestroyAPIView): ...@@ -667,7 +660,6 @@ class ProductDetail(generics.RetrieveUpdateDestroyAPIView):
if (self.request != None): if (self.request != None):
if (self.request.data.get("price") != None) and (self.request.data.get("modal") != None): if (self.request.data.get("price") != None) and (self.request.data.get("modal") != None):
instance=self.get_object()
draft_request_data = self.request.data.copy() draft_request_data = self.request.data.copy()
profit= int(self.request.data['price'])-int(self.request.data['modal']) profit= int(self.request.data['price'])-int(self.request.data['modal'])
new_profit={'profit': profit} new_profit={'profit': profit}
......
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