Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
PPL Sosial
pilar
pilar-backend
Commits
7fb056a3
Commit
7fb056a3
authored
Jun 06, 2021
by
Ilma Ainur Rohma
Browse files
PBI-14 : Membuat pre-order pada produk
parent
330690cc
Changes
10
Hide whitespace changes
Inline
Side-by-side
api/migrations/0004_
bankaccounttransferdestination_bank_code_numb
er.py
→
api/migrations/0004_
product_preord
er.py
View file @
7fb056a3
# 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_numb
er'
,
field
=
models
.
CharField
(
default
=
'000'
,
max_length
=
100
,
verbose_name
=
'
bank code numb
er'
),
model_name
=
'
product
'
,
name
=
'
preord
er'
,
field
=
models
.
BooleanField
(
blank
=
True
,
default
=
False
,
null
=
True
,
verbose_name
=
'
preord
er'
),
),
]
api/migrations/0005_product_preorder_duration.py
0 → 100644
View file @
7fb056a3
# 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'
),
),
]
api/migrations/0006_auto_20210603_1954.py
0 → 100644
View file @
7fb056a3
# 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'
),
),
]
api/migrations/0007_auto_20210603_2001.py
0 → 100644
View file @
7fb056a3
# 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'
),
),
]
api/migrations/000
5
_auto_20210
504_15
41.py
→
api/migrations/000
8
_auto_20210
605_22
41.py
View file @
7fb056a3
# Generated by Django 3.0.7 on 2021-0
5
-0
4 08
:41
# Generated by Django 3.0.7 on 2021-0
6
-0
5 15
:41
from
django.db
import
migrations
,
models
...
...
@@ -6,10 +6,15 @@ from django.db import migrations, models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'000
4_bankaccounttransferdestination_bank_code_number
'
),
(
'api'
,
'000
7_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'
,
...
...
api/models.py
View file @
7fb056a3
...
...
@@ -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'
)
...
...
api/seeds.py
View file @
7fb056a3
...
...
@@ -38,6 +38,8 @@ PRODUCT_DATA = {
'stock'
:
10
,
'modal'
:
'1000'
,
'unit'
:
'kg'
,
'preorder'
:
True
,
'preorder_duration'
:
5
,
}
TRANSACTION_DATA
=
{
...
...
api/serializers.py
View file @
7fb056a3
...
...
@@ -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'
]
...
...
api/tests.py
View file @
7fb056a3
...
...
@@ -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
)
...
...
api/views/product.py
View file @
7fb056a3
...
...
@@ -110,18 +110,31 @@ class ProductList(generics.ListCreateAPIView):
validated_image
=
serializer
.
validated_data
[
'image'
]
except
KeyError
:
pass
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'
]),
total_profit
=
0
,
unit
=
serializer
.
validated_data
[
'unit'
],
image
=
validated_image
)
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'
]),
total_profit
=
0
,
unit
=
serializer
.
validated_data
[
'unit'
],
image
=
validated_image
,
)
product
.
profit
=
(
product
.
price
-
product
.
modal
)
product
.
save
()
return
response
.
Response
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment