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
007b06cf
Commit
007b06cf
authored
Dec 29, 2020
by
Rayhan Muzakki
💬
Browse files
Bugfixing
parent
97b3dae1
Changes
8
Hide whitespace changes
Inline
Side-by-side
api/migrations/0002_auto_2020122
0
_1
630
.py
→
api/migrations/0002_auto_2020122
9
_1
028
.py
View file @
007b06cf
# Generated by Django 3.0.7 on 2020-12-2
0
0
9:30
# Generated by Django 3.0.7 on 2020-12-2
9
0
3: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'
,
...
...
api/models.py
View file @
007b06cf
...
...
@@ -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
:
...
...
api/reports_writer.py
View file @
007b06cf
...
...
@@ -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
(
...
...
api/seeds.py
View file @
007b06cf
...
...
@@ -99,7 +99,7 @@ SHIPMENT_CONFIG_DATA = {
BATCH_DATA
=
{
'batch_name'
:
'Batch 1'
,
'start_date'
:
'2020-12-
19
'
,
'end_date'
:
'202
0-12-25
'
,
'start_date'
:
'2020-12-
26
'
,
'end_date'
:
'202
1-01-01
'
,
'shipping_cost'
:
'60000'
,
}
api/serializers.py
View file @
007b06cf
...
...
@@ -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'
,
]
...
...
api/signals.py
View file @
007b06cf
...
...
@@ -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
...
...
api/tests.py
View file @
007b06cf
...
...
@@ -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'
,
...
...
api/views.py
View file @
007b06cf
...
...
@@ -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
}
...
...
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