From e7c7bdcd00fcc3f73b28a20ca1b008c296d3a2a3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 15 Jul 2021 16:42:28 +1000 Subject: [PATCH] Refactor BOM page --- InvenTree/part/templates/part/bom.html | 144 +--------------------- InvenTree/part/templates/part/detail.html | 127 +++++++++++++++++++ InvenTree/part/templates/part/navbar.html | 2 +- InvenTree/part/views.py | 2 +- 4 files changed, 133 insertions(+), 142 deletions(-) diff --git a/InvenTree/part/templates/part/bom.html b/InvenTree/part/templates/part/bom.html index 048b98fc01..4376c23ab9 100644 --- a/InvenTree/part/templates/part/bom.html +++ b/InvenTree/part/templates/part/bom.html @@ -1,16 +1,5 @@ -{% extends "part/part_base.html" %} -{% load static %} {% load i18n %} - -{% block menubar %} -{% include 'part/navbar.html' with tab='bom' %} -{% endblock %} - -{% block heading %} -{% trans "Bill of Materials" %} -{% endblock %} - -{% block details %} +{% load inventree_extras %} {% if roles.part.change != True and editing_enabled %}
@@ -32,7 +21,7 @@
{% endif %} -
+
{% if editing_enabled %}
- +
-{% endif %} - -{% endblock %} - -{% block js_ready %} -{{ block.super }} - - // Load the BOM table data - loadBomTable($("#bom-table"), { - editable: {{ editing_enabled }}, - bom_url: "{% url 'api-bom-list' %}", - part_url: "{% url 'api-part-list' %}", - parent_id: {{ part.id }} , - sub_part_detail: true, - }); - - linkButtonsToSelection($("#bom-table"), - [ - "#bom-item-delete", - ] - ); - - {% if editing_enabled %} - $("#editing-finished").click(function() { - location.href = "{% url 'part-bom' part.id %}"; - }); - - $('#bom-item-delete').click(function() { - - // Get a list of the selected BOM items - var rows = $("#bom-table").bootstrapTable('getSelections'); - - // TODO - In the future, display (in the dialog) which items are going to be deleted - - showQuestionDialog( - '{% trans "Delete selected BOM items?" %}', - '{% trans "All selected BOM items will be deleted" %}', - { - accept: function() { - - // Keep track of each DELETE request - var requests = []; - - rows.forEach(function(row) { - requests.push( - inventreeDelete( - `/api/bom/${row.pk}/`, - ) - ); - }); - - // Wait for *all* the requests to complete - $.when.apply($, requests).then(function() { - location.reload(); - }); - } - } - ); - }); - - $('#bom-upload').click(function() { - location.href = "{% url 'upload-bom' part.id %}"; - }); - - $('#bom-duplicate').click(function() { - launchModalForm( - "{% url 'duplicate-bom' part.id %}", - { - success: function() { - $('#bom-table').bootstrapTable('refresh'); - } - } - ); - }); - - $("#bom-item-new").click(function () { - launchModalForm( - "{% url 'bom-item-create' %}?parent={{ part.id }}", - { - success: function() { - $("#bom-table").bootstrapTable('refresh'); - }, - secondary: [ - { - field: 'sub_part', - label: '{% trans "New Part" %}', - title: '{% trans "Create New Part" %}', - url: "{% url 'part-create' %}", - }, - ] - } - ); - }); - - {% else %} - - $("#validate-bom").click(function() { - launchModalForm( - "{% url 'bom-validate' part.id %}", - { - reload: true, - } - ); - }); - - $("#edit-bom").click(function () { - location.href = "{% url 'part-bom' part.id %}?edit=1"; - }); - - $("#download-bom").click(function () { - launchModalForm("{% url 'bom-export' part.id %}", - { - success: function(response) { - location.href = response.url; - }, - } - ); - }); - - {% endif %} - - $("#print-bom-report").click(function() { - printBomReports([{{ part.pk }}]); - }); - -{% endblock %} +{% endif %} \ No newline at end of file diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index afef20d714..3def22cf03 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -229,6 +229,15 @@
+
+
+

{% trans "Bill of Materials" %}

+
+
+ {% include "part/bom.html" with part=part %} +
+
+

{% trans "Part Builds" %}

@@ -285,6 +294,124 @@ {% block js_ready %} {{ block.super }} + // Load the BOM table data + loadBomTable($("#bom-table"), { + editable: {{ editing_enabled }}, + bom_url: "{% url 'api-bom-list' %}", + part_url: "{% url 'api-part-list' %}", + parent_id: {{ part.id }} , + sub_part_detail: true, + }); + + linkButtonsToSelection($("#bom-table"), + [ + "#bom-item-delete", + ] + ); + + {% if editing_enabled %} + $("#editing-finished").click(function() { + location.href = "{% url 'part-detail' part.id %}?display=bom"; + }); + + $('#bom-item-delete').click(function() { + + // Get a list of the selected BOM items + var rows = $("#bom-table").bootstrapTable('getSelections'); + + // TODO - In the future, display (in the dialog) which items are going to be deleted + + showQuestionDialog( + '{% trans "Delete selected BOM items?" %}', + '{% trans "All selected BOM items will be deleted" %}', + { + accept: function() { + + // Keep track of each DELETE request + var requests = []; + + rows.forEach(function(row) { + requests.push( + inventreeDelete( + `/api/bom/${row.pk}/`, + ) + ); + }); + + // Wait for *all* the requests to complete + $.when.apply($, requests).then(function() { + location.reload(); + }); + } + } + ); + }); + + $('#bom-upload').click(function() { + location.href = "{% url 'upload-bom' part.id %}"; + }); + + $('#bom-duplicate').click(function() { + launchModalForm( + "{% url 'duplicate-bom' part.id %}", + { + success: function() { + $('#bom-table').bootstrapTable('refresh'); + } + } + ); + }); + + $("#bom-item-new").click(function () { + launchModalForm( + "{% url 'bom-item-create' %}?parent={{ part.id }}", + { + success: function() { + $("#bom-table").bootstrapTable('refresh'); + }, + secondary: [ + { + field: 'sub_part', + label: '{% trans "New Part" %}', + title: '{% trans "Create New Part" %}', + url: "{% url 'part-create' %}", + }, + ] + } + ); + }); + + {% else %} + + $("#validate-bom").click(function() { + launchModalForm( + "{% url 'bom-validate' part.id %}", + { + reload: true, + } + ); + }); + + $("#edit-bom").click(function () { + location.href = "{% url 'part-detail' part.id %}?display=bom&edit=1"; + }); + + $("#download-bom").click(function () { + launchModalForm("{% url 'bom-export' part.id %}", + { + success: function(response) { + location.href = response.url; + }, + } + ); + }); + + {% endif %} + + $("#print-bom-report").click(function() { + printBomReports([{{ part.pk }}]); + }); + $("#start-build").click(function() { newBuildOrder({ part: {{ part.pk }}, diff --git a/InvenTree/part/templates/part/navbar.html b/InvenTree/part/templates/part/navbar.html index dbd9423a02..e9d11207ed 100644 --- a/InvenTree/part/templates/part/navbar.html +++ b/InvenTree/part/templates/part/navbar.html @@ -41,7 +41,7 @@ {% endif %} {% if part.assembly %}
  • - + {% trans "Bill of Materials" %} diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 1ebd37a469..bf8c32ba78 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -1441,7 +1441,7 @@ class BomUpload(InvenTreeRoleMixin, FileManagementFormView): # BomItem already exists pass - return HttpResponseRedirect(reverse('part-bom', kwargs={'pk': self.kwargs['pk']})) + return HttpResponseRedirect(reverse('part-detail', kwargs={'pk': self.kwargs['pk']})) class PartExport(AjaxView):