Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PixieDust-LastMinuteSurpluss
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Erick Gabriel T. Lopez
PixieDust-LastMinuteSurpluss
Commits
566836b0
Commit
566836b0
authored
Dec 06, 2022
by
Bryan Carlo Guanlao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Orders App edit
edited order_item model fields and fixed discount bugs
parent
d2fb0a10
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
21 deletions
+84
-21
admin.py
pixie_dust/orders/admin.py
+6
-2
0003_rename_color_orderitem_item_color.py
...ders/migrations/0003_rename_color_orderitem_item_color.py
+18
-0
0004_alter_orderitem_discount.py
...e_dust/orders/migrations/0004_alter_orderitem_discount.py
+19
-0
models.py
pixie_dust/orders/models.py
+41
-19
No files found.
pixie_dust/orders/admin.py
View file @
566836b0
...
...
@@ -2,13 +2,17 @@ from django.contrib import admin
from
.models
import
Order
,
OrderItem
# Register your models here.
class
OrderAdmin
(
admin
.
ModelAdmin
):
model
=
Order
list_display
=
(
'order_no'
,
'order_date'
,
'amount_due'
,
)
class
OrderItemAdmin
(
admin
.
ModelAdmin
):
model
=
OrderItem
list_display
=
(
'order_no'
,
'item_id'
,
'color'
,
'quantity'
,
'sub_total'
,
'is_successful'
)
list_display
=
(
'order_no'
,
'item_id'
,
'item_color'
,
'quantity'
,
'sub_total'
,
'is_successful'
)
admin
.
site
.
register
(
Order
,
OrderAdmin
)
...
...
pixie_dust/orders/migrations/0003_rename_color_orderitem_item_color.py
0 → 100644
View file @
566836b0
# Generated by Django 3.2.12 on 2022-12-06 05:37
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'orders'
,
'0002_alter_orderitem_discount'
),
]
operations
=
[
migrations
.
RenameField
(
model_name
=
'orderitem'
,
old_name
=
'color'
,
new_name
=
'item_color'
,
),
]
pixie_dust/orders/migrations/0004_alter_orderitem_discount.py
0 → 100644
View file @
566836b0
# Generated by Django 3.2.12 on 2022-12-06 06:21
import
django.core.validators
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'orders'
,
'0003_rename_color_orderitem_item_color'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'orderitem'
,
name
=
'discount'
,
field
=
models
.
IntegerField
(
default
=
0
,
help_text
=
'in percentage'
,
validators
=
[
django
.
core
.
validators
.
MaxValueValidator
(
100
),
django
.
core
.
validators
.
MinValueValidator
(
0
)]),
),
]
pixie_dust/orders/models.py
View file @
566836b0
...
...
@@ -6,48 +6,70 @@ from datetime import date
from
decimal
import
*
# Create your models here.
class
Order
(
models
.
Model
):
order_no
=
models
.
AutoField
(
primary_key
=
True
)
order_date
=
models
.
DateField
(
auto_now_add
=
True
)
customer_id
=
models
.
ForeignKey
(
Customer
,
on_delete
=
models
.
CASCADE
,
db_column
=
'customer_id'
)
items
=
models
.
ManyToManyField
(
Product
,
through
=
'OrderItem'
,
through_fields
=
(
'order_no'
,
'item_id'
))
customer_id
=
models
.
ForeignKey
(
Customer
,
on_delete
=
models
.
CASCADE
,
db_column
=
'customer_id'
)
items
=
models
.
ManyToManyField
(
Product
,
through
=
'OrderItem'
,
through_fields
=
(
'order_no'
,
'item_id'
))
delivery_schedule
=
models
.
DateTimeField
()
delivery_address
=
models
.
CharField
(
max_length
=
254
)
as_gift
=
models
.
BooleanField
(
help_text
=
'Is this order intended as a Gift?'
)
recipient
=
models
.
CharField
(
max_length
=
50
,
help_text
=
'Type your name if order is not intended as a gift.'
)
amount_due
=
models
.
DecimalField
(
default
=
0
,
editable
=
False
,
decimal_places
=
2
,
max_digits
=
12
)
as_gift
=
models
.
BooleanField
(
help_text
=
'Is this order intended as a Gift?'
)
recipient
=
models
.
CharField
(
max_length
=
50
,
help_text
=
'Type your name if order is not intended as a gift.'
)
amount_due
=
models
.
DecimalField
(
default
=
0
,
editable
=
False
,
decimal_places
=
2
,
max_digits
=
12
)
def
__str__
(
self
):
return
str
(
self
.
order_no
)
class
Meta
:
db_table
=
"order"
class
OrderItem
(
models
.
Model
):
order_no
=
models
.
ForeignKey
(
Order
,
on_delete
=
models
.
CASCADE
,
db_column
=
'order_no'
)
item_id
=
models
.
ForeignKey
(
Product
,
on_delete
=
models
.
CASCADE
,
db_column
=
'item_id'
)
color
=
models
.
CharField
(
max_length
=
20
,
choices
=
((
"RED"
,
"Red"
),
(
"ORANGE"
,
"Orange"
),
(
"YELLOW"
,
"Yellow"
),
order_no
=
models
.
ForeignKey
(
Order
,
on_delete
=
models
.
CASCADE
,
db_column
=
'order_no'
)
item_id
=
models
.
ForeignKey
(
Product
,
on_delete
=
models
.
CASCADE
,
db_column
=
'item_id'
)
item_color
=
models
.
CharField
(
max_length
=
20
,
choices
=
((
"RED"
,
"Red"
),
(
"ORANGE"
,
"Orange"
),
(
"YELLOW"
,
"Yellow"
),
(
"GREEN"
,
"Green"
),
(
"BLUE"
,
"Blue"
),
(
"PURPLE"
,
"Purple"
),
(
"PINK"
,
"Pink"
),
(
"BLACK"
,
"Black"
)))
quantity
=
models
.
IntegerField
(
default
=
1
,
validators
=
[
MaxValueValidator
(
99
),
MinValueValidator
(
0
)])
quantity
=
models
.
IntegerField
(
default
=
1
,
validators
=
[
MaxValueValidator
(
99
),
MinValueValidator
(
0
)])
personalization
=
models
.
CharField
(
max_length
=
254
)
discount
=
models
.
IntegerField
(
default
=
0
,
validators
=
[
MaxValueValidator
(
100
),
MinValueValidator
(
0
)])
discount_price
=
models
.
DecimalField
(
default
=
0
,
decimal_places
=
2
,
max_digits
=
12
)
sub_total
=
models
.
DecimalField
(
default
=
0
,
editable
=
False
,
decimal_places
=
2
,
max_digits
=
12
)
discount
=
models
.
IntegerField
(
default
=
0
,
validators
=
[
MaxValueValidator
(
100
),
MinValueValidator
(
0
)],
help_text
=
'in percentage'
)
discount_price
=
models
.
DecimalField
(
default
=
0
,
decimal_places
=
2
,
max_digits
=
12
,
editable
=
False
)
sub_total
=
models
.
DecimalField
(
default
=
0
,
editable
=
False
,
decimal_places
=
2
,
max_digits
=
12
)
is_successful
=
models
.
BooleanField
(
default
=
True
,
editable
=
False
)
def
save
(
self
,
*
args
,
**
kwargs
):
import
products.models
as
product_model
inventory
=
product_model
.
Inventory
.
objects
.
all
()
product
=
product_model
.
Product
.
objects
.
all
()
for
prod
in
inventory
:
if
(
prod
.
item_id
==
self
.
item_id
and
prod
.
color
==
self
.
color
):
if
(
prod
.
quantity
<
self
.
quantity
):
if
(
prod
.
item_id
==
self
.
item_id
and
prod
.
color
==
self
.
item_
color
):
if
(
prod
.
stock
<
self
.
quantity
):
self
.
is_successful
=
False
else
:
prod
.
quantity
-=
self
.
quantity
prod
.
stock
-=
self
.
quantity
prod
.
save
()
if
(
self
.
is_successful
):
self
.
sub_total
=
self
.
discount_price
*
self
.
quantity
self
.
discount_price
=
self
.
item_id
.
price
*
\
(
1
-
(
self
.
discount
/
100
))
self
.
sub_total
=
self
.
discount_price
*
self
.
quantity
self
.
order_no
.
amount_due
+=
Decimal
(
self
.
sub_total
)
self
.
order_no
.
save
()
return
super
()
.
save
(
*
args
,
**
kwargs
)
def
__str__
(
self
):
return
str
(
self
.
quantity
)
+
" pcs. of "
+
str
(
self
.
item_id
)
+
" of variant "
+
self
.
color
.
lower
()
+
" added to order #"
+
str
(
self
.
order_no
)
return
str
(
self
.
quantity
)
+
" pcs. of "
+
str
(
self
.
item_id
)
+
" of variant "
+
self
.
item_color
.
lower
()
+
" added to order #"
+
str
(
self
.
order_no
)
class
Meta
:
db_table
=
"order_item"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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