Fakultas Ilmu Komputer UI

Commit d11f6f95 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!104
parents 97b3dae1 007b06cf
# 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
from decimal import Decimal
......@@ -16,6 +16,14 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RemoveField(
model_name='product',
name='pre_order',
),
migrations.RemoveField(
model_name='transactionitem',
name='product_pre_order',
),
migrations.AddField(
model_name='product',
name='modal',
......
......@@ -133,7 +133,7 @@ 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'),
......@@ -141,7 +141,6 @@ class Product(db_models.Model):
validators=[validators.MinValueValidator(decimal.Decimal('0.01'))],
verbose_name=_('modal')
)
profit= db_models.DecimalField(
blank=True,
null=True,
......@@ -170,11 +169,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
......@@ -376,7 +370,7 @@ 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(
......
......@@ -99,7 +99,7 @@ SHIPMENT_CONFIG_DATA = {
BATCH_DATA = {
'batch_name': 'Batch 1',
'start_date': '2020-12-19',
'end_date': '2020-12-25',
'start_date': '2020-12-26',
'end_date': '2021-01-01',
'shipping_cost': '60000',
}
......@@ -261,7 +261,6 @@ class ProductSerializer(serializers.ModelSerializer):
'description',
'price',
'stock',
'pre_order',
'modal',
'profit',
'image',
......@@ -270,16 +269,7 @@ 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):
......@@ -318,7 +308,6 @@ class TransactionItemSerializer(serializers.ModelSerializer):
'product_code',
'product_name',
'product_price',
'product_pre_order',
'quantity',
]
model = models.TransactionItem
......@@ -327,7 +316,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',
......
......@@ -172,14 +172,7 @@ class CartCheckout(rest_framework_views.APIView):
transaction_status = (
'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(
user=user,
payment_method=serializer.validated_data['payment_method'],
......@@ -667,7 +660,6 @@ class ProductDetail(generics.RetrieveUpdateDestroyAPIView):
if (self.request != 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()
profit= int(self.request.data['price'])-int(self.request.data['modal'])
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