From be41741b1e5d4250c707b037879701d36357a090 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 14 Jan 2021 14:37:49 +1100 Subject: [PATCH] Bug fix for cancelling purchase orders --- InvenTree/order/models.py | 6 +++++- InvenTree/order/templates/order/order_base.html | 2 +- InvenTree/order/views.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 184452f24e..23d07a0c2e 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -257,7 +257,11 @@ class PurchaseOrder(Order): self.save() def can_cancel(self): - return self.status not in [ + """ + A PurchaseOrder can only be cancelled under the following circumstances: + """ + + return self.status in [ PurchaseOrderStatus.PLACED, PurchaseOrderStatus.PENDING ] diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index d3e1e02437..fa45bbfe41 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -47,7 +47,7 @@ src="{% static 'img/blank_image.png' %}" {% endif %} - {% if order.status == PurchaseOrderStatus.PENDING or order.status == PurchaseOrderStatus.PLACED %} + {% if order.can_cancel %} diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index bd758e39fb..091b11e825 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -432,7 +432,7 @@ class PurchaseOrderCancel(AjaxUpdateView): form.add_error('confirm', _('Confirm order cancellation')) if not order.can_cancel(): - form.add_error(None, _('Order cannot be cancelled as either pending or placed')) + form.add_error(None, _('Order cannot be cancelled')) def save(self, order, form, **kwargs): """