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.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):

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>
{% endif %}
</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>
<p>{{ order.description }}</p>
<div class='btn-row'>
@ -72,7 +77,12 @@ src="{% static 'img/blank_image.png' %}"
<tr>
<td><span class='fas fa-info'></span></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>
<td><span class='fas fa-building'></span></td>
@ -105,6 +115,13 @@ src="{% static 'img/blank_image.png' %}"
<td>{{ order.issue_date }}</td>
</tr>
{% 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 %}
<tr>
<td><span class='fas fa-calendar-alt'></span></td>