Fakultas Ilmu Komputer UI

Commit 7fb056a3 authored by Ilma Ainur Rohma's avatar Ilma Ainur Rohma
Browse files

PBI-14 : Membuat pre-order pada produk

parent 330690cc
# Generated by Django 3.0.7 on 2021-05-04 07:41
# Generated by Django 3.0.7 on 2021-05-21 15:02
from django.db import migrations, models
......@@ -11,8 +11,8 @@ class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='bankaccounttransferdestination',
name='bank_code_number',
field=models.CharField(default='000', max_length=100, verbose_name='bank code number'),
model_name='product',
name='preorder',
field=models.BooleanField(blank=True, default=False, null=True, verbose_name='preorder'),
),
]
# Generated by Django 3.0.7 on 2021-05-21 16:37
from decimal import Decimal
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0004_product_preorder'),
]
operations = [
migrations.AddField(
model_name='product',
name='preorder_duration',
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='preorder duration'),
),
]
# Generated by Django 3.0.7 on 2021-06-03 12:54
from decimal import Decimal
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0005_product_preorder_duration'),
]
operations = [
migrations.AlterField(
model_name='product',
name='preorder_duration',
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0'), max_digits=12, null=True, validators=[django.core.validators.MinValueValidator(Decimal('1'))], verbose_name='preorder duration'),
),
]
# Generated by Django 3.0.7 on 2021-06-03 13:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0006_auto_20210603_1954'),
]
operations = [
migrations.AlterField(
model_name='product',
name='preorder_duration',
field=models.PositiveIntegerField(blank=True, default=0, null=True, verbose_name='preorder duration'),
),
]
# Generated by Django 3.0.7 on 2021-05-04 08:41
# Generated by Django 3.0.7 on 2021-06-05 15:41
from django.db import migrations, models
......@@ -6,10 +6,15 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0004_bankaccounttransferdestination_bank_code_number'),
('api', '0007_auto_20210603_2001'),
]
operations = [
migrations.AddField(
model_name='bankaccounttransferdestination',
name='bank_code_number',
field=models.CharField(default='000', max_length=100, verbose_name='bank code number'),
),
migrations.AddField(
model_name='programdonation',
name='transfer_destination_bank_code_number',
......
......@@ -156,7 +156,7 @@ class Product(db_models.Model):
upload_to=utils.get_upload_file_path,
verbose_name=_('image')
)
total_profit= db_models.DecimalField(
total_profit = db_models.DecimalField(
blank=True,
null=True,
default=decimal.Decimal('0'),
......@@ -166,6 +166,13 @@ class Product(db_models.Model):
verbose_name=_('total profit')
)
unit = db_models.CharField(default='buah', max_length=200, verbose_name=_('unit'))
preorder = db_models.BooleanField(blank=True, null=True, default=False, verbose_name=_('preorder'))
preorder_duration = db_models.PositiveIntegerField(
blank=True,
null=True,
default=0,
verbose_name=_('preorder duration')
)
class Meta:
ordering = ['subcategory', 'name', 'code', 'id']
verbose_name = _('product')
......
......@@ -38,6 +38,8 @@ PRODUCT_DATA = {
'stock': 10,
'modal': '1000',
'unit': 'kg',
'preorder' : True,
'preorder_duration' : 5,
}
TRANSACTION_DATA = {
......
......@@ -265,7 +265,9 @@ class ProductSerializer(serializers.ModelSerializer):
'profit',
'image',
'total_profit',
'unit'
'unit',
'preorder',
'preorder_duration'
]
model = models.Product
read_only_fields = ['id', 'code']
......
......@@ -1204,6 +1204,8 @@ class ProductTest(rest_framework_test.APITestCase):
self.assertEqual(models.Product.objects.count(), 1)
self.assertEqual(models.Product.objects.get(id=response.data['id']).name, data['name'])
self.assertEqual(models.Product.objects.get(id=response.data['id']).unit, data['unit'])
self.assertEqual(models.Product.objects.get(id=response.data['id']).preorder, data['preorder'])
self.assertEqual(models.Product.objects.get(id=response.data['id']).preorder_duration, data['preorder_duration'])
def test_create_product_fail(self):
data = dict(seeds.PRODUCT_DATA, subcategory=self.subcategory.id)
......
......@@ -110,17 +110,30 @@ class ProductList(generics.ListCreateAPIView):
validated_image = serializer.validated_data['image']
except KeyError:
pass
if serializer.validated_data['preorder']:
product = models.Product.objects.create(
name=serializer.validated_data['name'],
description=serializer.validated_data['description'],
price=serializer.validated_data['price'],
modal=serializer.validated_data['modal'],
subcategory=models.Subcategory.objects.get(name=serializer.validated_data['subcategory']),
total_profit=0,
unit=serializer.validated_data['unit'],
image=validated_image,
preorder=serializer.validated_data['preorder'],
preorder_duration=serializer.validated_data['preorder_duration'],
)
else:
product = models.Product.objects.create(
name=serializer.validated_data['name'],
description=serializer.validated_data['description'],
price=serializer.validated_data['price'],
stock=serializer.validated_data['stock'],
modal=serializer.validated_data['modal'],
subcategory=models.Subcategory.objects.get(
name=serializer.validated_data['subcategory']),
subcategory=models.Subcategory.objects.get(name=serializer.validated_data['subcategory']),
total_profit=0,
unit=serializer.validated_data['unit'],
image=validated_image
image=validated_image,
)
product.profit = (product.price - product.modal)
product.save()
......
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