From 7f2804dff319cf4348d9951d16d3bc64bc020fb4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 5 Dec 2019 10:29:16 +1100 Subject: [PATCH] Add button to mark a purchase order as complete, even if not all line items are received --- InvenTree/order/forms.py | 11 ++++++ InvenTree/order/models.py | 6 ++++ .../order/templates/order/order_complete.html | 13 +++++++ .../order/purchase_order_detail.html | 11 ++++++ InvenTree/order/urls.py | 1 + InvenTree/order/views.py | 36 +++++++++++++++++++ 6 files changed, 78 insertions(+) create mode 100644 InvenTree/order/templates/order/order_complete.html diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 8432d9a6ef..97e0f0bdd9 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -27,6 +27,17 @@ class IssuePurchaseOrderForm(HelperForm): ] +class CompletePurchaseOrderForm(HelperForm): + + confirm = forms.BooleanField(required=False, help_text=_("Mark order as complete")) + + class Meta: + model = PurchaseOrder + fields = [ + 'confirm', + ] + + class CancelPurchaseOrderForm(HelperForm): confirm = forms.BooleanField(required=False, help_text=_('Cancel order')) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index b1b93b990a..c0be887fe1 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -188,6 +188,12 @@ class PurchaseOrder(Order): return self.lines.filter(quantity__gt=F('received')) + @property + def is_complete(self): + """ Return True if all line items have been received """ + + return self.pending_line_items().count() == 0 + @transaction.atomic def receive_line_item(self, line, location, quantity, user): """ Receive a line item (or partial line item) against this PO diff --git a/InvenTree/order/templates/order/order_complete.html b/InvenTree/order/templates/order/order_complete.html new file mode 100644 index 0000000000..f6b9f14338 --- /dev/null +++ b/InvenTree/order/templates/order/order_complete.html @@ -0,0 +1,13 @@ +{% extends "modal_form.html" %} + +{% block pre_form_content %} + +Mark this order as complete? +{% if not order.is_complete %} +
+ This order has line items which have not been marked as received. + Marking this order as complete will remove these line items. +
+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 0ee447ef0e..d7d34103b1 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -44,6 +44,9 @@ InvenTree | {{ order }} + {% endif %} {% if order.status == OrderStatus.PENDING or order.status == OrderStatus.PLACED %}