From 984e16d5aff6e575159311889bb50c292bffe00a Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 15 Jul 2021 16:07:46 +1000 Subject: [PATCH] Return all part parameters to the main part edit form - refactor purchaseorder view - refactor salesorder view --- InvenTree/InvenTree/static/css/inventree.css | 2 +- InvenTree/part/api.py | 2 +- InvenTree/part/templates/part/detail.html | 65 ++++++++++++++ InvenTree/part/templates/part/orders.html | 51 ----------- InvenTree/part/templates/part/part_base.html | 75 +--------------- .../part/templates/part/sales_orders.html | 41 --------- InvenTree/part/test_views.py | 15 ---- InvenTree/part/urls.py | 3 - InvenTree/part/views.py | 34 ------- InvenTree/templates/js/nav.js | 5 -- InvenTree/templates/js/part.js | 88 +++++++++++++++++++ 11 files changed, 156 insertions(+), 225 deletions(-) delete mode 100644 InvenTree/part/templates/part/orders.html delete mode 100644 InvenTree/part/templates/part/sales_orders.html diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index b538aaad04..1c8d529a92 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -781,7 +781,7 @@ input[type="submit"] { } .sidenav .list-group-item.active { - background-color: #bbab8b; + background-color: #b3a997; border-color: #ccc; } diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 599c4bba5d..9abee816fa 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -1104,7 +1104,7 @@ part_api_urls = [ url(r'^(?P\d+)/?', PartThumbsUpdate.as_view(), name='api-part-thumbs-update'), ])), - url(r'^(?P\d+)/?', PartDetail.as_view(), name='api-part-detail'), + url(r'^(?P\d+)/', PartDetail.as_view(), name='api-part-detail'), url(r'^.*$', PartList.as_view(), name='api-part-list'), ] diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 1f217a872c..5b377708f6 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -44,6 +44,48 @@ +
+
+

{% trans "Purchase Orders" %}

+
+
+
+
+ +
+ +
+
+
+ + +
+
+
+ +
+
+

{% trans "Sales Orders" %}

+
+
+
+
+ {% if 0 %} + + {% endif %} +
+ +
+
+
+ + +
+
+
+
@@ -101,6 +143,29 @@ {% block js_ready %} {{ block.super }} + loadPurchaseOrderTable($("#purchase-order-table"), { + url: "{% url 'api-po-list' %}", + params: { + part: {{ part.id }}, + }, + }); + + $("#part-order2").click(function() { + launchModalForm("{% url 'order-parts' %}", { + data: { + part: {{ part.id }}, + }, + reload: true, + }); + }); + + loadSalesOrderTable($("#sales-order-table"), { + url: "{% url 'api-so-list' %}", + params: { + part: {{ part.id }}, + }, + }); + loadPartTestTemplateTable( $("#test-template-table"), { diff --git a/InvenTree/part/templates/part/orders.html b/InvenTree/part/templates/part/orders.html deleted file mode 100644 index 24a1cdbf3c..0000000000 --- a/InvenTree/part/templates/part/orders.html +++ /dev/null @@ -1,51 +0,0 @@ -{% extends "part/part_base.html" %} -{% load static %} -{% load i18n %} - -{% block menubar %} -{% include 'part/navbar.html' with tab='orders' %} -{% endblock %} - -{% block heading %} -{% trans "Purchase Orders" %} -{% endblock %} - -{% block details %} - -
-
- -
- -
-
-
- - -
- - -{% endblock %} - -{% block js_ready %} -{{ block.super }} - -loadPurchaseOrderTable($("#purchase-order-table"), { - url: "{% url 'api-po-list' %}", - params: { - part: {{ part.id }}, - }, -}); - -$("#part-order2").click(function() { - launchModalForm("{% url 'order-parts' %}", { - data: { - part: {{ part.id }}, - }, - reload: true, - }); -}); - -{% endblock %} \ No newline at end of file diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index e7ec892628..efbd7d2b0b 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -421,80 +421,7 @@ $("#part-edit").click(function() { - constructForm('{% url "api-part-detail" part.id %}', { - focus: 'name', - fields: { - category: { - secondary: { - label: '{% trans "New Category" %}', - title: '{% trans "Create New Part Category" %}', - api_url: '{% url "api-part-category-list" %}', - method: 'POST', - fields: { - name: {}, - description: {}, - parent: { - secondary: { - title: '{% trans "New Parent" %}', - api_url: '{% url "api-part-category-list" %}', - method: 'POST', - fields: { - name: {}, - description: {}, - parent: {}, - } - } - }, - } - }, - }, - name: { - placeholder: 'part name', - }, - IPN: {}, - description: {}, - revision: {}, - keywords: { - icon: 'fa-key', - }, - variant_of: {}, - link: { - icon: 'fa-link', - }, - default_location: { - secondary: { - label: '{% trans "New Location" %}', - title: '{% trans "Create new stock location" %}', - - }, - }, - default_supplier: { - filters: { - part: {{ part.pk }}, - part_detail: true, - manufacturer_detail: true, - supplier_detail: true, - }, - secondary: { - label: '{% trans "New Supplier Part" %}', - title: '{% trans "Create new supplier part" %}', - } - }, - units: {}, - minimum_stock: {}, - }, - title: '{% trans "Edit Part" %}', - reload: true, - }); - - return; - - launchModalForm( - "{% url 'part-edit' part.id %}", - { - reload: true, - } - ); + editPart({{ part.pk }}); }); {% endif %} diff --git a/InvenTree/part/templates/part/sales_orders.html b/InvenTree/part/templates/part/sales_orders.html deleted file mode 100644 index fa8d5dfd8a..0000000000 --- a/InvenTree/part/templates/part/sales_orders.html +++ /dev/null @@ -1,41 +0,0 @@ -{% extends "part/part_base.html" %} -{% load static %} -{% load i18n %} - -{% block menubar %} -{% include 'part/navbar.html' with tab='sales-orders' %} -{% endblock %} - -{% block heading %} -{% trans "Sales Orders" %} -{% endblock %} - -{% block details %} - -
-
- {% if 0 %} - - {% endif %} -
- -
-
-
- - -
- -{% endblock %} - -{% block js_ready %} -{{ block.super }} - -loadSalesOrderTable($("#sales-order-table"), { - url: "{% url 'api-so-list' %}", - params: { - part: {{ part.id }}, - }, -}); - -{% endblock %} diff --git a/InvenTree/part/test_views.py b/InvenTree/part/test_views.py index 3b6b245231..9779aac544 100644 --- a/InvenTree/part/test_views.py +++ b/InvenTree/part/test_views.py @@ -158,21 +158,6 @@ class PartDetailTest(PartViewTestCase): class PartTests(PartViewTestCase): """ Tests for Part forms """ - def test_part_edit(self): - - response = self.client.get(reverse('part-edit', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest') - - keys = response.context.keys() - data = str(response.content) - - self.assertEqual(response.status_code, 200) - - self.assertIn('part', keys) - self.assertIn('csrf_token', keys) - - self.assertIn('html_form', data) - self.assertIn('"title":', data) - def test_part_create(self): """ Launch form to create a new part """ response = self.client.get(reverse('part-create'), {'category': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 8aa254e126..7ea4ca4eff 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -36,7 +36,6 @@ part_parameter_urls = [ ] part_detail_urls = [ - url(r'^edit/?', views.PartEdit.as_view(), name='part-edit'), url(r'^delete/?', views.PartDelete.as_view(), name='part-delete'), url(r'^bom-export/?', views.BomExport.as_view(), name='bom-export'), url(r'^bom-download/?', views.BomDownload.as_view(), name='bom-download'), @@ -55,8 +54,6 @@ part_detail_urls = [ url(r'^used/?', views.PartDetail.as_view(template_name='part/used_in.html'), name='part-used-in'), url(r'^prices/', views.PartPricingView.as_view(template_name='part/prices.html'), name='part-prices'), url(r'^suppliers/?', views.PartDetail.as_view(template_name='part/supplier.html'), name='part-suppliers'), - url(r'^orders/?', views.PartDetail.as_view(template_name='part/orders.html'), name='part-orders'), - url(r'^sales-orders/', views.PartDetail.as_view(template_name='part/sales_orders.html'), name='part-sales-orders'), url(r'^track/?', views.PartDetail.as_view(template_name='part/track.html'), name='part-track'), url(r'^related-parts/?', views.PartDetail.as_view(template_name='part/related.html'), name='part-related'), diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 4acf5fcdb6..1ebd37a469 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -1084,40 +1084,6 @@ class PartImageSelect(AjaxUpdateView): return self.renderJsonResponse(request, form, data) -class PartEdit(AjaxUpdateView): - """ View for editing Part object """ - - model = Part - form_class = part_forms.EditPartForm - ajax_template_name = 'modal_form.html' - ajax_form_title = _('Edit Part Properties') - context_object_name = 'part' - - def get_form(self): - """ Create form for Part editing. - Overrides default get_form() method to limit the choices - for the 'default_supplier' field to SupplierParts that reference this part - """ - - form = super(AjaxUpdateView, self).get_form() - - # Hide the "default expiry" field if the feature is not enabled - if not inventree_settings.stock_expiry_enabled(): - form.fields['default_expiry'].widget = HiddenInput() - - part = self.get_object() - - form.fields['default_supplier'].queryset = SupplierPart.objects.filter(part=part) - - # Check if IPN can be edited - ipn_edit_enable = InvenTreeSetting.get_setting('PART_ALLOW_EDIT_IPN') - if not ipn_edit_enable and not self.request.user.is_superuser: - # Admin can still change IPN - form.fields['IPN'].disabled = True - - return form - - class BomDuplicate(AjaxUpdateView): """ View for duplicating BOM from a parent item. diff --git a/InvenTree/templates/js/nav.js b/InvenTree/templates/js/nav.js index 7dc562b8ef..f33571d584 100644 --- a/InvenTree/templates/js/nav.js +++ b/InvenTree/templates/js/nav.js @@ -56,15 +56,10 @@ function activatePanel(panelName, options={}) { // Iterate through the available 'select' elements until one matches panelName = null; - console.log("no match for panel:", panelName); - $('.nav-toggle').each(function(item) { var panel_name = $(this).attr('id').replace('select-', ''); - console.log("checking:", panel_name); - if ($(`#panel-${panel_name}`).length && (panelName == null)) { - console.log("found match -", panel_name); panelName = panel_name; } diff --git a/InvenTree/templates/js/part.js b/InvenTree/templates/js/part.js index e106098ad4..7f034682de 100644 --- a/InvenTree/templates/js/part.js +++ b/InvenTree/templates/js/part.js @@ -13,6 +13,94 @@ function yesNoLabel(value) { } } + +function editPart(pk, options={}) { + + var url = `/api/part/${pk}/`; + + var fields = { + category: { + /* + secondary: { + label: '{% trans "New Category" %}', + title: '{% trans "Create New Part Category" %}', + api_url: '{% url "api-part-category-list" %}', + method: 'POST', + fields: { + name: {}, + description: {}, + parent: { + secondary: { + title: '{% trans "New Parent" %}', + api_url: '{% url "api-part-category-list" %}', + method: 'POST', + fields: { + name: {}, + description: {}, + parent: {}, + } + } + }, + } + }, + */ + }, + name: { + placeholder: 'part name', + }, + IPN: {}, + description: {}, + revision: {}, + keywords: { + icon: 'fa-key', + }, + variant_of: {}, + link: { + icon: 'fa-link', + }, + default_location: { + /* + secondary: { + label: '{% trans "New Location" %}', + title: '{% trans "Create new stock location" %}', + }, + */ + }, + default_supplier: { + filters: { + part: pk, + part_detail: true, + manufacturer_detail: true, + supplier_detail: true, + }, + /* + secondary: { + label: '{% trans "New Supplier Part" %}', + title: '{% trans "Create new supplier part" %}', + } + */ + }, + units: {}, + minimum_stock: {}, + virtual: {}, + is_template: {}, + assembly: {}, + component: {}, + trackable: {}, + purchaseable: {}, + salable: {}, + active: {}, + }; + + constructForm(url, { + fields: fields, + title: '{% trans "Edit Part" %}', + reload: true, + }); + +} + + function toggleStar(options) { /* Toggle the 'starred' status of a part. * Performs AJAX queries and updates the display on the button.