diff --git a/core/__init__.py b/core/__init__.py index efb4c27..2cd15a8 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -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: # The order was created with the specified context. CREATED = 'CREATED' diff --git a/core/models.py b/core/models.py index 7519732..4235d53 100644 --- a/core/models.py +++ b/core/models.py @@ -24,6 +24,7 @@ from . import ( VoucherType, TransactionStatus, OrderStatus, + ShippingStatus, ShippingProvider, ShippingContainer ) @@ -397,6 +398,15 @@ class Order(models.Model): 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): for line in self.lines.all(): line.minus_stock() diff --git a/dashboard/templates/dashboard/order/_table.html b/dashboard/templates/dashboard/order/_table.html index 2cb5272..4a830bf 100644 --- a/dashboard/templates/dashboard/order/_table.html +++ b/dashboard/templates/dashboard/order/_table.html @@ -3,7 +3,8 @@