Display overdue status on PurcahseOrder page

This commit is contained in:
Oliver Walters 2021-01-14 17:42:38 +11:00
parent a8e6d0a89f
commit 21e8ddd1e6
2 changed files with 35 additions and 10 deletions

View File

@ -273,6 +273,18 @@ class PurchaseOrder(Order):
self.complete_date = datetime.now().date() self.complete_date = datetime.now().date()
self.save() 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): def can_cancel(self):
""" """
A PurchaseOrder can only be cancelled under the following circumstances: A PurchaseOrder can only be cancelled under the following circumstances:
@ -440,17 +452,13 @@ class SalesOrder(Order):
""" """
Returns true if this SalesOrder is "overdue": Returns true if this SalesOrder is "overdue":
- Not completed Makes use of the OVERDUE_FILTER to avoid code duplication.
- Target date is "in the past"
""" """
# Order cannot be deemed overdue if target_date is not set query = SalesOrder.objects.filter(pk=self.pk)
if self.target_date is None: query = query.filer(SalesOrder.OVERDUE_FILTER)
return False
today = datetime.now().date() return query.exists()
return self.is_pending and self.target_date < today
@property @property
def is_pending(self): def is_pending(self):

View File

@ -26,7 +26,12 @@ src="{% static 'img/blank_image.png' %}"
<a href="{% url 'admin:order_purchaseorder_change' order.pk %}"><span title='{% trans "Admin view" %}' class='fas fa-user-shield'></span></a> <a href="{% url 'admin:order_purchaseorder_change' order.pk %}"><span title='{% trans "Admin view" %}' class='fas fa-user-shield'></span></a>
{% endif %} {% endif %}
</h3> </h3>
<h3>{% purchase_order_status_label order.status large=True %}</h3> <h3>
{% purchase_order_status_label order.status large=True %}
{% if order.is_overdue %}
<span class='label label-large label-large-red'>{% trans "Overdue" %}</span>
{% endif %}
</h3>
<hr> <hr>
<p>{{ order.description }}</p> <p>{{ order.description }}</p>
<div class='btn-row'> <div class='btn-row'>
@ -72,7 +77,12 @@ src="{% static 'img/blank_image.png' %}"
<tr> <tr>
<td><span class='fas fa-info'></span></td> <td><span class='fas fa-info'></span></td>
<td>{% trans "Order Status" %}</td> <td>{% trans "Order Status" %}</td>
<td>{% purchase_order_status_label order.status %}</td> <td>
{% purchase_order_status_label order.status %}
{% if order.is_overdue %}
<span class='label label-red'>{% trans "Overdue" %}</span>
{% endif %}
</td>
</tr> </tr>
<tr> <tr>
<td><span class='fas fa-building'></span></td> <td><span class='fas fa-building'></span></td>
@ -105,6 +115,13 @@ src="{% static 'img/blank_image.png' %}"
<td>{{ order.issue_date }}</td> <td>{{ order.issue_date }}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if order.target_date %}
<tr>
<td><span class='fas fa-calendar-alt'></span></td>
<td>{% trans "Target Date" %}</td>
<td>{{ order.target_date }}</td>
</tr>
{% endif %}
{% if order.status == PurchaseOrderStatus.COMPLETE %} {% if order.status == PurchaseOrderStatus.COMPLETE %}
<tr> <tr>
<td><span class='fas fa-calendar-alt'></span></td> <td><span class='fas fa-calendar-alt'></span></td>