Add shipment status to order list

This commit is contained in:
Nathan Chapman 2023-03-20 13:57:02 -06:00
parent 0bf982e7f8
commit ed3c93418c
3 changed files with 35 additions and 1 deletions

View File

@ -49,6 +49,18 @@ class OrderStatus:
] ]
class ShippingStatus:
NOT_SHIPPED = 'Not shipped'
PARTIALLY_SHIPPED = 'Partially shipped'
SHIPPED = 'Shipped'
CHOICES = [
(NOT_SHIPPED, 'Not shipped'),
(PARTIALLY_SHIPPED, 'Partially shipped'),
(SHIPPED, 'Shipped'),
]
class TransactionStatus: class TransactionStatus:
# The order was created with the specified context. # The order was created with the specified context.
CREATED = 'CREATED' CREATED = 'CREATED'

View File

@ -24,6 +24,7 @@ from . import (
VoucherType, VoucherType,
TransactionStatus, TransactionStatus,
OrderStatus, OrderStatus,
ShippingStatus,
ShippingProvider, ShippingProvider,
ShippingContainer ShippingContainer
) )
@ -397,6 +398,15 @@ class Order(models.Model):
objects = OrderManager() objects = OrderManager()
def get_shipping_status(self):
has_tracking = self.tracking_numbers.count() > 0
if has_tracking and self.status == OrderStatus.FULFILLED:
return ShippingStatus.SHIPPED
elif has_tracking and self.status == OrderStatus.PARTIALLY_FULFILLED:
return ShippingStatus.PARTIALLY_SHIPPED
return ShippingStatus.NOT_SHIPPED
def minus_stock(self): def minus_stock(self):
for line in self.lines.all(): for line in self.lines.all():
line.minus_stock() line.minus_stock()

View File

@ -3,7 +3,8 @@
<th>Order No.</th> <th>Order No.</th>
<th>Date</th> <th>Date</th>
<th>Customer</th> <th>Customer</th>
<th>Status</th> <th>Fulfillment</th>
<th>Shipping</th>
<th>Total</th> <th>Total</th>
</tr> </tr>
</thead> </thead>
@ -18,6 +19,17 @@
<span class="status-dot status-{{order.status}}"></span> {{order.get_status_display}} <span class="status-dot status-{{order.status}}"></span> {{order.get_status_display}}
</div> </div>
</td> </td>
<td>
<div class="status-display">
{% if order.get_shipping_status == "Shipped" %}
<span class="status-dot status-success"></span> {{ order.get_shipping_status }}
{% elif order.get_shipping_status == "Partially shipped" %}
<span class="status-dot status-warning"></span> {{ order.get_shipping_status }}
{% else %}
<span class="status-dot status-info"></span> {{ order.get_shipping_status }}
{% endif %}
</div>
</td>
<td>${{order.total_amount}}</td> <td>${{order.total_amount}}</td>
</tr> </tr>
{% endfor %} {% endfor %}