Skip to content

Commit d9f4d7c

Browse files
Merge pull request #391 from MySecondLanguage/refactored
Refactored
2 parents aa65e36 + b474833 commit d9f4d7c

File tree

10 files changed

+181
-20
lines changed

10 files changed

+181
-20
lines changed

nxtbn/core/enum_perms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class PermissionsEnum(models.TextChoices):
55
CAN_APPROVE_ORDER = "can_approve_order"
66
CAN_CANCEL_ORDER = "can_cancel_order"
77
CAN_SHIP_ORDER = "can_ship_order"
8-
CAN_PROCCSS_ORDER = "can_process_order"
8+
CAN_PACK_ORDER = "can_pack_order"
99
CAN_DELIVER_ORDER = "can_deliver_order"
1010
CAN_UPDATE_ORDER_PYMENT_TERM = "can_update_order_payment_term"
1111
CAN_UPDATE_ORDER_PAYMENT_METHOD = "can_update_order_payment_method"

nxtbn/order/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class OrderStatus(models.TextChoices):
3232
"""Defines the different stages of an order's lifecycle.
3333
3434
- 'PENDING': Order has been placed but not yet processed.
35-
- 'PROCESSING': Order is being processed and prepared for shipment.
35+
- 'PACKED': Order has been processed and is has packed for shipment.
3636
- 'SHIPPED': Order has been shipped but not yet delivered.
3737
- 'DELIVERED': Order has been delivered to the customer.
3838
- 'CANCELLED': Order has been cancelled and will not be fulfilled.
@@ -41,7 +41,7 @@ class OrderStatus(models.TextChoices):
4141

4242
PENDING = "PENDING", _("Pending")
4343
APPROVED = "APPROVED", _("Approved")
44-
PROCESSING = "PROCESSING", _("Processing")
44+
PACKED = "PACKED", _("Packed")
4545
SHIPPED = "SHIPPED", _("Shipped")
4646
DELIVERED = "DELIVERED", _("Delivered")
4747
CANCELLED = "CANCELLED", _("Cancelled")
@@ -156,4 +156,4 @@ class OrderStockReservationStatus(models.TextChoices):
156156
RELEASED = 'RELEASED', _('Released')
157157
FAILED = 'FAILED', _('Failed')
158158
NOT_RESERVED = 'NOT_RESERVED', _('Not Reserved')
159-
SHIPPED = 'SHIPPED', _('Shipped')
159+
DISPATCHED = 'DISPATCHED', _('Dispatched')

nxtbn/order/api/dashboard/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def validate(self, attrs):
202202
elif current_status not in [OrderStatus.PENDING, OrderStatus.APPROVED]:
203203
raise serializers.ValidationError(_(f"{current_status.value} orders cannot be cancelled."))
204204

205-
if new_status == OrderStatus.PROCESSING:
205+
if new_status == OrderStatus.PACKED:
206206
if current_status != OrderStatus.APPROVED:
207-
raise serializers.ValidationError(_("Only pending orders can be started to processing."))
207+
raise serializers.ValidationError(_("Only pending orders can be started for packing."))
208208

209209
if new_status == OrderStatus.SHIPPED:
210210
if current_status == OrderStatus.CANCELLED:

nxtbn/order/api/dashboard/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def check_permissions(self, request):
436436
OrderStatus.SHIPPED: PermissionsEnum.CAN_SHIP_ORDER,
437437
OrderStatus.DELIVERED: PermissionsEnum.CAN_DELIVER_ORDER,
438438
OrderStatus.APPROVED: PermissionsEnum.CAN_APPROVE_ORDER,
439-
OrderStatus.PROCESSING: PermissionsEnum.CAN_PROCCSS_ORDER,
439+
OrderStatus.PACKED: PermissionsEnum.CAN_PACK_ORDER,
440440
}
441441

442442
required_permission = permission_map.get(status)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 4.2.11 on 2025-02-17 08:00
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("order", "0035_alter_order_options"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="order",
15+
name="status",
16+
field=models.CharField(
17+
choices=[
18+
("PENDING", "Pending"),
19+
("APPROVED", "Approved"),
20+
("PACKED", "Packed"),
21+
("SHIPPED", "Shipped"),
22+
("DELIVERED", "Delivered"),
23+
("CANCELLED", "Cancelled"),
24+
("PENDING_RETURN", "Pending Return"),
25+
("RETURNED", "Returned"),
26+
],
27+
default="PENDING",
28+
help_text="Represents the current stage of the order within its lifecycle.",
29+
max_length=20,
30+
verbose_name="Order Status",
31+
),
32+
),
33+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 4.2.11 on 2025-02-17 08:07
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("order", "0036_alter_order_status"),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name="order",
15+
options={
16+
"ordering": ("-created_at",),
17+
"permissions": [
18+
("can_approve_order", "Can approve order"),
19+
("can_cancel_order", "Can cancel order"),
20+
("can_ship_order", "Can ship order"),
21+
("can_pack_order", "Can process order"),
22+
("can_deliver_order", "Can deliver order"),
23+
("can_update_order_payment_term", "Can update order payment term"),
24+
(
25+
"can_update_order_payment_method",
26+
"Can update order payment method",
27+
),
28+
],
29+
},
30+
),
31+
]

nxtbn/order/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class Meta:
254254
(PermissionsEnum.CAN_APPROVE_ORDER, 'Can approve order'),
255255
(PermissionsEnum.CAN_CANCEL_ORDER, 'Can cancel order'),
256256
(PermissionsEnum.CAN_SHIP_ORDER, 'Can ship order'),
257-
(PermissionsEnum.CAN_PROCCSS_ORDER, 'Can process order'),
257+
(PermissionsEnum.CAN_PACK_ORDER, 'Can process order'),
258258
(PermissionsEnum.CAN_DELIVER_ORDER, 'Can deliver order'),
259259
(PermissionsEnum.CAN_UPDATE_ORDER_PYMENT_TERM, 'Can update order payment term'),
260260
(PermissionsEnum.CAN_UPDATE_ORDER_PAYMENT_METHOD, 'Can update order payment method'),

nxtbn/order/tests/test_order_reservation_cancel_shipped_merge_return_sc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_order_stock_tracking_with_disallowed_backorder_return(self):
109109
# Now Ship the successfull order
110110
order_status_update_url = reverse('order-status-update', args=[order_less_than_stock_response_with_stock_tracking.data['order_alias']])
111111
approve = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.APPROVED}, format='json')
112-
processing = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.PROCESSING}, format='json')
112+
processing = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.PACKED}, format='json')
113113
approved = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.SHIPPED}, format='json')
114114

115115
self.assertEqual(approve.status_code, status.HTTP_200_OK)
@@ -251,7 +251,7 @@ def test_order_back_order_allowed(self):
251251
# Now Ship the successfull order
252252
order_status_update_url = reverse('order-status-update', args=[order_out_of_stock_response_with_stock_tracking_bo.data['order_alias']])
253253
approve = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.APPROVED}, format='json')
254-
processing = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.PROCESSING}, format='json')
254+
processing = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.PACKED}, format='json')
255255
shipped = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.SHIPPED}, format='json')
256256

257257
self.assertEqual(approve.status_code, status.HTTP_200_OK)
@@ -385,7 +385,7 @@ def test_order_without_tracking_stock(self):
385385
# Now Ship the successfull order
386386
order_status_update_url = reverse('order-status-update', args=[order_response.data['order_alias']])
387387
approve = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.APPROVED}, format='json')
388-
processing = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.PROCESSING}, format='json')
388+
processing = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.PACKED}, format='json')
389389
shipped = self.auth_client.patch(order_status_update_url, {"status": OrderStatus.SHIPPED}, format='json')
390390

391391
self.assertEqual(approve.status_code, status.HTTP_200_OK)

nxtbn/warehouse/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def deduct_reservation_on_dispatch(order):
127127
# Remove the reservation
128128
reservation.delete()
129129

130-
order.reservation_status = OrderStockReservationStatus.SHIPPED
130+
order.reservation_status = OrderStockReservationStatus.DISPATCHED
131131
order.save()
132132
return order
133133

templates/dashboard.html

Lines changed: 105 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,115 @@
33

44
<head>
55
<meta charset="utf-8" />
6-
<link rel="icon" href="https://cdn.nxtbn.com/1.0.0/favicon.ico" />
6+
<link rel="icon" href="https://cdn.nxtbn.com/2.0.0/favicon.ico" />
77
<meta name="viewport" content="width=device-width,initial-scale=1" />
8-
<meta name="theme-color" content="#000000" />
8+
<meta name="theme-color" content="#0caf60" />
99
<meta name="description" content="Powered by NXTBN - Blazing Fast" />
10-
<link rel="apple-touch-icon" href="https://cdn.nxtbn.com/1.0.0/logo192.png" />
11-
<link rel="manifest" href="https://cdn.nxtbn.com/1.0.0/manifest.json" />
12-
<title>NXTBN - Solution for mission criticle Online Shop</title>
13-
<script defer="defer" src="https://cdn.nxtbn.com/1.0.0/static/js/main.js"></script>
14-
<link href="https://cdn.nxtbn.com/1.0.0/static/css/main.css" rel="stylesheet">
10+
<link rel="apple-touch-icon" href="https://cdn.nxtbn.com/2.0.0/logo192.png" />
11+
<link rel="manifest" href="https://cdn.nxtbn.com/2.0.0/manifest.json" />
12+
<title>NXTBN - Solution for Mission-Critical Online Shop</title>
13+
<script defer="defer" src="https://cdn.nxtbn.com/2.0.0/static/js/main.js"></script>
14+
<link href="https://cdn.nxtbn.com/2.0.0/static/css/main.css" rel="stylesheet">
15+
16+
<style>
17+
#preloader {
18+
position: fixed;
19+
top: 0;
20+
left: 0;
21+
width: 100%;
22+
height: 100%;
23+
background: rgb(12, 175, 96, 0.9);
24+
color: white;
25+
display: flex;
26+
flex-direction: column;
27+
align-items: center;
28+
justify-content: center;
29+
z-index: 9999;
30+
font-family: Arial, sans-serif;
31+
text-align: center;
32+
}
33+
34+
#progress-bar {
35+
width: 80%;
36+
height: 6px;
37+
background: rgba(255, 255, 255, 0.2);
38+
margin-top: 15px;
39+
border-radius: 4px;
40+
overflow: hidden;
41+
}
42+
43+
#progress-fill {
44+
width: 0%;
45+
height: 100%;
46+
background: rgb(255, 255, 255);
47+
transition: width 0.3s ease-in-out;
48+
}
49+
50+
#loading-text {
51+
font-size: 20px;
52+
font-weight: bold;
53+
margin-bottom: 10px;
54+
}
55+
56+
#loading-percentage {
57+
font-size: 16px;
58+
margin-top: 10px;
59+
}
60+
</style>
61+
62+
<script>
63+
document.addEventListener("DOMContentLoaded", function () {
64+
let percentage = 0;
65+
const messages = [
66+
"Preparing Store...",
67+
"Optimizing Performance...",
68+
"Loading Data...",
69+
"Finalizing Setup..."
70+
];
71+
let messageIndex = 0;
72+
73+
function updateLoader() {
74+
if (percentage >= 100) {
75+
document.getElementById("preloader").style.display = "none";
76+
} else {
77+
percentage += Math.floor(Math.random() * 10 + 5);
78+
if (percentage > 100) percentage = 100;
79+
80+
document.getElementById("loading-percentage").textContent = percentage + "%";
81+
document.getElementById("progress-fill").style.width = percentage + "%";
82+
83+
if (percentage > (messageIndex + 1) * 30 && messageIndex < messages.length - 1) {
84+
messageIndex++;
85+
document.getElementById("loading-text").textContent = messages[messageIndex];
86+
}
87+
88+
setTimeout(updateLoader, 500);
89+
}
90+
}
91+
92+
updateLoader();
93+
94+
95+
window.addEventListener("load", function () {
96+
setTimeout(() => {
97+
document.getElementById("preloader").style.display = "none";
98+
}, 500);
99+
});
100+
});
101+
</script>
15102
</head>
16103

17-
<body><noscript>You need to enable JavaScript to run this app.</noscript>
104+
<body>
105+
<noscript>You need to enable JavaScript to run this app.</noscript>
106+
107+
<div id="preloader">
108+
<h2 id="loading-text">Setting up your high-performance store dashboard, please wait...</h2>
109+
<div id="progress-bar">
110+
<div id="progress-fill"></div>
111+
</div>
112+
<p id="loading-percentage">0%</p>
113+
</div>
114+
18115
<div id="root"></div>
19116
</body>
20117

0 commit comments

Comments
 (0)