From 96eb4086cfc0b602119532f0afae2d39c7caef2d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 5 Jun 2019 22:24:18 +1000 Subject: [PATCH] Add form / view to edit purchase order details - Cannot edit the COMPANY if there are line items already --- InvenTree/order/forms.py | 27 +++++++++++++- .../order/templates/order/order_issue.html | 1 + .../order/templates/order/order_status.html | 10 +++--- .../order/purchase_order_detail.html | 15 ++++++++ InvenTree/order/urls.py | 3 ++ InvenTree/order/views.py | 36 ++++++++++++++++--- InvenTree/static/css/inventree.css | 1 - 7 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 InvenTree/order/templates/order/order_issue.html diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index f80a4436a5..bdd77e15bc 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -7,10 +7,35 @@ from __future__ import unicode_literals from InvenTree.forms import HelperForm -from .models import PurchaseOrderLineItem +from .models import PurchaseOrder, PurchaseOrderLineItem + + +class IssuePurchaseOrderForm(HelperForm): + + class Meta: + model = PurchaseOrder + fields = [ + 'status', + ] + + +class EditPurchaseOrderForm(HelperForm): + """ Form for editing a PurchaseOrder object """ + + class Meta: + model = PurchaseOrder + fields = [ + 'reference', + 'supplier', + 'description', + 'URL', + 'status', + 'notes' + ] class EditPurchaseOrderLineItemForm(HelperForm): + """ Form for editing a PurchaseOrderLineItem object """ class Meta: model = PurchaseOrderLineItem diff --git a/InvenTree/order/templates/order/order_issue.html b/InvenTree/order/templates/order/order_issue.html new file mode 100644 index 0000000000..c7de8c74b2 --- /dev/null +++ b/InvenTree/order/templates/order/order_issue.html @@ -0,0 +1 @@ +{% extends "modal_form.html" %} \ No newline at end of file diff --git a/InvenTree/order/templates/order/order_status.html b/InvenTree/order/templates/order/order_status.html index 3e3d2a1e08..c9e13cac24 100644 --- a/InvenTree/order/templates/order/order_status.html +++ b/InvenTree/order/templates/order/order_status.html @@ -1,13 +1,13 @@ {% if order.status == OrderStatus.PENDING %} - + {% elif order.status == OrderStatus.PLACED %} - + {% elif order.status == OrderStatus.COMPLETE %} - + {% elif order.status == OrderStatus.CANCELLED or order.status == OrderStatus.RETURNED %} - + {% else %} - + {% endif %} {{ order.get_status_display }} \ 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 4593c6d9b1..dbabb2f940 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -55,6 +55,13 @@ InvenTree | {{ order }}
+
+ + {% if order.status == OrderStatus.PENDING %} + + {% endif %} +
+

Order Items

@@ -96,6 +103,14 @@ InvenTree | {{ order }} {% block js_ready %} +$("#edit-order").click(function() { + launchModalForm("{% url 'purchase-order-edit' order.id %}", + { + reload: true, + } + ); +}); + $('#new-po-line').click(function() { launchModalForm("{% url 'po-line-item-create' %}", { diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index 9aa350fc54..16ca858e39 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -11,6 +11,9 @@ from . import views purchase_order_detail_urls = [ + url(r'^edit/?', views.PurchaseOrderEdit.as_view(), name='purchase-order-edit'), + url(r'^issue/?', views.PurchaseOrderIssue.as_view(), name='purchase-order-issue'), + url(r'^.*$', views.PurchaseOrderDetail.as_view(), name='purchase-order-detail'), ] diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index d7b47abf1a..6bacdda93e 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -9,7 +9,8 @@ from django.views.generic import DetailView, ListView from django.forms import HiddenInput from .models import PurchaseOrder, PurchaseOrderLineItem -from .forms import EditPurchaseOrderLineItemForm + +from . import forms as order_forms from InvenTree.views import AjaxCreateView, AjaxUpdateView @@ -46,14 +47,41 @@ class PurchaseOrderDetail(DetailView): return ctx +class PurchaseOrderEdit(AjaxUpdateView): + """ View for editing a PurchaseOrder using a modal form """ + + model = PurchaseOrder + ajax_form_title = 'Edit Purchase Order' + form_class = order_forms.EditPurchaseOrderForm + + def get_form(self): + + form = super(AjaxUpdateView, self).get_form() + + order = self.get_object() + + if order.lines.count() > 0: + form.fields['supplier'].widget = HiddenInput() + + return form + + +class PurchaseOrderIssue(AjaxUpdateView): + """ View for changing a purchase order from 'PENDING' to 'ISSUED' """ + + model = PurchaseOrder + ajax_form_title = 'Issue Order' + ajax_template_name = "order/order_issue.html" + form_class = order_forms.IssuePurchaseOrderForm + + class POLineItemCreate(AjaxCreateView): """ AJAX view for creating a new PurchaseOrderLineItem object """ model = PurchaseOrderLineItem context_object_name = 'line' - form_class = EditPurchaseOrderLineItemForm - ajax_template_name = 'modal_form.html' + form_class = order_forms.EditPurchaseOrderLineItemForm ajax_form_title = 'Add Line Item' def get_form(self): @@ -113,6 +141,6 @@ class POLineItemCreate(AjaxCreateView): class POLineItemEdit(AjaxUpdateView): model = PurchaseOrderLineItem - form_class = EditPurchaseOrderLineItemForm + form_class = order_forms.EditPurchaseOrderLineItemForm ajax_template_name = 'modal_form.html' ajax_form_action = 'Edit Line Item' diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css index 794676ca68..3bef992d34 100644 --- a/InvenTree/static/css/inventree.css +++ b/InvenTree/static/css/inventree.css @@ -38,7 +38,6 @@ /* Extra label styles */ .label-large { - padding: 5px; margin: 3px; font-size: 100%; }