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
85b35c4f
Commit
85b35c4f
authored
Mar 29, 2021
by
Bunga Amalia Kurniawati
🌺
Committed by
Azhar Difa Arnanda
Mar 29, 2021
Browse files
PBI-4: Menambahkan kolom satuan pada model Produk
parent
11a91da4
Changes
5
Hide whitespace changes
Inline
Side-by-side
api/migrations/0003_product_unit.py
0 → 100644
View file @
85b35c4f
# Generated by Django 3.0.7 on 2021-03-27 05:42
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0002_auto_20201229_1028'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'product'
,
name
=
'unit'
,
field
=
models
.
CharField
(
default
=
'buah'
,
max_length
=
200
,
verbose_name
=
'unit'
),
),
]
api/models.py
View file @
85b35c4f
...
...
@@ -164,6 +164,7 @@ class Product(db_models.Model):
validators
=
[
validators
.
MinValueValidator
(
decimal
.
Decimal
(
'0.01'
))],
verbose_name
=
_
(
'total profit'
)
)
unit
=
db_models
.
CharField
(
default
=
'buah'
,
max_length
=
200
,
verbose_name
=
_
(
'unit'
))
class
Meta
:
ordering
=
[
'subcategory'
,
'name'
,
'code'
,
'id'
]
verbose_name
=
_
(
'product'
)
...
...
api/seeds.py
View file @
85b35c4f
...
...
@@ -35,7 +35,8 @@ PRODUCT_DATA = {
'description'
:
'Dummy description.'
,
'price'
:
'2000'
,
'stock'
:
10
,
'modal'
:
'1000'
,
'modal'
:
'1000'
,
'unit'
:
'kg'
,
}
TRANSACTION_DATA
=
{
...
...
api/serializers.py
View file @
85b35c4f
...
...
@@ -264,7 +264,8 @@ class ProductSerializer(serializers.ModelSerializer):
'modal'
,
'profit'
,
'image'
,
'total_profit'
'total_profit'
,
'unit'
]
model
=
models
.
Product
read_only_fields
=
[
'id'
,
'code'
]
...
...
api/tests.py
View file @
85b35c4f
...
...
@@ -1169,6 +1169,7 @@ class ProductTest(rest_framework_test.APITestCase):
def
test_create_product_success
(
self
):
data
=
seeds
.
PRODUCT_DATA
data
[
'subcategory'
]
=
self
.
subcategory
.
id
data
[
'unit'
]
=
'kg'
response
=
request
(
'POST'
,
...
...
@@ -1184,6 +1185,7 @@ class ProductTest(rest_framework_test.APITestCase):
def
test_create_product_fail
(
self
):
data
=
dict
(
seeds
.
PRODUCT_DATA
,
subcategory
=
self
.
subcategory
.
id
)
data
[
'name'
]
=
None
data
[
'unit'
]
=
None
response
=
request
(
'POST'
,
'product-list'
,
...
...
@@ -1200,7 +1202,8 @@ class ProductTest(rest_framework_test.APITestCase):
data
=
{
'name'
:
'Dummy'
,
'price'
:
'4000'
,
'modal'
:
'2000'
'modal'
:
'2000'
,
'unit'
:
'gram'
}
response
=
request
(
'PATCH'
,
...
...
@@ -1229,6 +1232,7 @@ class ProductTest(rest_framework_test.APITestCase):
))
data
=
{
'name'
:
''
,
'unit'
:
''
}
response
=
request
(
'PATCH'
,
...
...
@@ -1239,7 +1243,6 @@ class ProductTest(rest_framework_test.APITestCase):
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
class
ShoppingCartTest
(
rest_framework_test
.
APITestCase
):
def
setUp
(
self
):
self
.
superuser
=
models
.
User
.
objects
.
create_superuser
(
**
seeds
.
SUPERUSER_DATA
)
...
...
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