From 7e5c9aa043a07baf26bcfc74abf62f78de81cc4e Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 2 Jul 2021 23:04:53 +1000 Subject: [PATCH] Refactor PurchaseOrderEdit form --- .../order/templates/order/order_base.html | 29 +++++++++++++++---- InvenTree/order/test_views.py | 6 ---- InvenTree/order/urls.py | 1 - InvenTree/order/views.py | 20 ------------- InvenTree/templates/js/forms.js | 7 ++++- InvenTree/templates/js/model_renderers.js | 21 ++++++++++++++ 6 files changed, 51 insertions(+), 33 deletions(-) diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index c7ba6be8a4..85d8fd5c51 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -164,11 +164,30 @@ $('#print-order-report').click(function() { }); $("#edit-order").click(function() { - launchModalForm("{% url 'po-edit' order.id %}", - { - reload: true, - } - ); + + constructForm('{% url "api-po-detail" order.pk %}', { + fields: { + reference: { + prefix: "{% settings_value 'PURCHASEORDER_REFERENCE_PREFIX' %}", + }, + {% if order.lines.count == 0 and order.status == PurchaseOrderStatus.PENDING %} + supplier: { + }, + {% endif %} + description: {}, + target_date: { + icon: 'fa-calendar-alt', + }, + link: { + icon: 'fa-link', + }, + responsible: { + icon: 'fa-user', + }, + }, + title: '{% trans "Edit Purchase Order" %}', + reload: true, + }); }); $("#receive-order").click(function() { diff --git a/InvenTree/order/test_views.py b/InvenTree/order/test_views.py index 23122d079d..b0bd8ce95d 100644 --- a/InvenTree/order/test_views.py +++ b/InvenTree/order/test_views.py @@ -168,12 +168,6 @@ class POTests(OrderViewTestCase): response = self.client.get(url, {'supplier': 'goat'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 200) - def test_po_edit(self): - """ Launch form to edit a PurchaseOrder """ - - response = self.client.get(reverse('po-edit', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - def test_po_export(self): """ Export PurchaseOrder """ diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index 3863d895c8..ce2421b684 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -12,7 +12,6 @@ from . import views purchase_order_detail_urls = [ url(r'^cancel/', views.PurchaseOrderCancel.as_view(), name='po-cancel'), - url(r'^edit/', views.PurchaseOrderEdit.as_view(), name='po-edit'), url(r'^issue/', views.PurchaseOrderIssue.as_view(), name='po-issue'), url(r'^receive/', views.PurchaseOrderReceive.as_view(), name='po-receive'), url(r'^complete/', views.PurchaseOrderComplete.as_view(), name='po-complete'), diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 04bd0d3828..647176862d 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -215,26 +215,6 @@ class SalesOrderCreate(AjaxCreateView): return super().save(form) -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() - - # Prevent user from editing supplier if there are already lines in the order - if order.lines.count() > 0 or not order.status == PurchaseOrderStatus.PENDING: - form.fields['supplier'].widget = HiddenInput() - - return form - - class SalesOrderEdit(AjaxUpdateView): """ View for editing a SalesOrder """ diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index 6081001740..5ac5dc2a38 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -383,6 +383,10 @@ function constructFormBody(fields, options) { } fields[field].hidden = field_options.hidden; + + if (field_options.read_only != null) { + fields[field].read_only = field_options.read_only; + } } } @@ -982,7 +986,6 @@ function initializeRelatedField(name, field, options) { select.select2({ placeholder: '', - allowClear: !field.required, dropdownParent: $(options.modal), dropdownAutoWidth: false, ajax: { @@ -1201,6 +1204,8 @@ function renderModelData(name, model, data, parameters, options) { case 'supplierpart': renderer = renderSupplierPart; break; + case 'owner': + renderer = renderOwner; default: break; } diff --git a/InvenTree/templates/js/model_renderers.js b/InvenTree/templates/js/model_renderers.js index 34c0ef1097..3ad9e44782 100644 --- a/InvenTree/templates/js/model_renderers.js +++ b/InvenTree/templates/js/model_renderers.js @@ -93,6 +93,27 @@ function renderPart(name, data, parameters, options) { } +// Renderer for "Owner" model +function renderOwner(name, data, parameters, options) { + + var html = `${data.name}`; + + + switch (data.label) { + case 'user': + html += ``; + break; + case 'group': + html += ``; + break; + default: + break; + } + + return html; +} + + // Renderer for "PartCategory" model function renderPartCategory(name, data, parameters, options) {