From 21e8ddd1e622f4bc9c5de1b923365630d69beff6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 14 Jan 2021 17:42:38 +1100 Subject: [PATCH] Display overdue status on PurcahseOrder page --- InvenTree/order/models.py | 24 ++++++++++++------- .../order/templates/order/order_base.html | 21 ++++++++++++++-- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 3a86cf4306..65729ab993 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -273,6 +273,18 @@ class PurchaseOrder(Order): self.complete_date = datetime.now().date() self.save() + def is_overdue(self): + """ + Returns True if this PurchaseOrder is "overdue" + + Makes use of the OVERDUE_FILTER to avoid code duplication. + """ + + query = PurchaseOrder.objects.filter(pk=self.pk) + query = query.filter(PurchaseOrder.OVERDUE_FILTER) + + return query.exists() + def can_cancel(self): """ A PurchaseOrder can only be cancelled under the following circumstances: @@ -440,17 +452,13 @@ class SalesOrder(Order): """ Returns true if this SalesOrder is "overdue": - - Not completed - - Target date is "in the past" + Makes use of the OVERDUE_FILTER to avoid code duplication. """ - # Order cannot be deemed overdue if target_date is not set - if self.target_date is None: - return False + query = SalesOrder.objects.filter(pk=self.pk) + query = query.filer(SalesOrder.OVERDUE_FILTER) - today = datetime.now().date() - - return self.is_pending and self.target_date < today + return query.exists() @property def is_pending(self): diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index fa45bbfe41..4e67325e48 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -26,7 +26,12 @@ src="{% static 'img/blank_image.png' %}" {% endif %} -

{% purchase_order_status_label order.status large=True %}

+

+ {% purchase_order_status_label order.status large=True %} + {% if order.is_overdue %} + {% trans "Overdue" %} + {% endif %} +


{{ order.description }}

@@ -72,7 +77,12 @@ src="{% static 'img/blank_image.png' %}" {% trans "Order Status" %} - {% purchase_order_status_label order.status %} + + {% purchase_order_status_label order.status %} + {% if order.is_overdue %} + {% trans "Overdue" %} + {% endif %} + @@ -105,6 +115,13 @@ src="{% static 'img/blank_image.png' %}" {{ order.issue_date }} {% endif %} + {% if order.target_date %} + + + {% trans "Target Date" %} + {{ order.target_date }} + + {% endif %} {% if order.status == PurchaseOrderStatus.COMPLETE %}