From 16b01ed772e3cd97bfba3509dc87dba05e845f2a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 20 Apr 2021 13:21:23 +1000 Subject: [PATCH] significant rework of the build allocation tables / views --- InvenTree/build/models.py | 36 ++++++ InvenTree/build/templates/build/allocate.html | 112 ++++-------------- .../templates/build/allocation_card.html | 12 +- .../build/templates/build/build_output.html | 78 +++++++++++- InvenTree/build/templates/build/navbar.html | 8 +- InvenTree/build/templates/build/parts.html | 30 ----- InvenTree/build/urls.py | 1 - InvenTree/build/views.py | 4 +- InvenTree/templates/js/build.js | 39 +++--- InvenTree/templates/two_column.html | 4 + 10 files changed, 176 insertions(+), 148 deletions(-) delete mode 100644 InvenTree/build/templates/build/parts.html diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index b9167b2eb0..963401a543 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -314,6 +314,42 @@ class Build(MPTTModel): 'sub_part' ) + @property + def tracked_bom_items(self): + """ + Returns the "trackable" BOM items for this BuildOrder + """ + + items = self.bom_items + items = items.filter(sub_part__trackable=True) + + return items + + def has_tracked_bom_items(self): + """ + Returns True if this BuildOrder has trackable BomItems + """ + + return self.tracked_bom_items.count() > 0 + + @property + def untracked_bom_items(self): + """ + Returns the "non trackable" BOM items for this BuildOrder + """ + + items = self.bom_items + items = items.filter(sub_part__trackable=False) + + return items + + def has_untracked_bom_items(self): + """ + Returns True if this BuildOrder has non trackable BomItems + """ + + return self.untracked_bom_items.count() > 0 + @property def remaining(self): """ diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index fb4a8200e7..a1e1ff2f8e 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -12,83 +12,32 @@ {% endblock %} {% block heading %} -{% trans "Incomplete Build Ouputs" %} +{% trans "Allocate Stock to Build" %} {% endblock %} {% block details %} -{% if build.is_complete %} -
- {% trans "Build order has been completed" %} -
-{% else %} +{% if build.has_untracked_bom_items %} +{% if build.active %}
- {% if build.active %} - - - {% endif %} -
- -
- -
- -
-
-
-
-
-
- -
- -{% if build.incomplete_outputs %} -
- {% for item in build.incomplete_outputs %} - {% include "build/allocation_card.html" with item=item %} - {% endfor %} -
-{% else %} -
- {% trans "Create a new build output" %}
- {% trans "No incomplete build outputs remain." %}
- {% trans "Create a new build output using the button above" %} + +
+{% endif %} +
+{% else %} +
+ {% trans "This Build Order does not have any associated untracked BOM items" %}
{% endif %} - -{% endif %} - {% endblock %} {% block js_ready %} @@ -101,22 +50,17 @@ part: {{ build.part.pk }}, }; + {% if build.has_untracked_bom_items %} // Load allocation table for un-tracked parts loadBuildOutputAllocationTable(buildInfo, null); + {% endif %} - {% for item in build.incomplete_outputs %} - // Get the build output as a javascript object - inventreeGet('{% url 'api-stock-detail' item.pk %}', {}, - { - success: function(response) { - loadBuildOutputAllocationTable(buildInfo, response); - } - } - ); - {% endfor %} + function reloadTable() { + $('#allocation-table-untracked').bootstrapTable('refresh'); + } {% if build.active %} - $("#btn-allocate").on('click', function() { + $("#btn-auto-allocate").on('click', function() { launchModalForm( "{% url 'build-auto-allocate' build.id %}", { @@ -124,20 +68,12 @@ } ); }); - + $('#btn-unallocate').on('click', function() { launchModalForm( "{% url 'build-unallocate' build.id %}", { - reload: true, - } - ); - }); - - $('#btn-create-output').click(function() { - launchModalForm('{% url "build-output-create" build.id %}', - { - reload: true, + success: reloadTable, } ); }); diff --git a/InvenTree/build/templates/build/allocation_card.html b/InvenTree/build/templates/build/allocation_card.html index 650257bb0d..3ce4a52aeb 100644 --- a/InvenTree/build/templates/build/allocation_card.html +++ b/InvenTree/build/templates/build/allocation_card.html @@ -7,23 +7,31 @@