From bf987f23f30b0e9008a60f9b374356c406fa6510 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 17 May 2019 00:14:29 +1000 Subject: [PATCH 01/10] Add 'tabbed' page set for Build app --- .../build/templates/build/build_base.html | 79 ++++++++++++++++ InvenTree/build/templates/build/detail.html | 92 +------------------ InvenTree/build/templates/build/required.html | 36 ++++++++ InvenTree/build/templates/build/tabs.html | 10 ++ InvenTree/build/urls.py | 2 + 5 files changed, 131 insertions(+), 88 deletions(-) create mode 100644 InvenTree/build/templates/build/build_base.html create mode 100644 InvenTree/build/templates/build/required.html create mode 100644 InvenTree/build/templates/build/tabs.html diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html new file mode 100644 index 0000000000..f790275d2e --- /dev/null +++ b/InvenTree/build/templates/build/build_base.html @@ -0,0 +1,79 @@ +{% extends "base.html" %} + +{% load static %} + +{% block page_title %} +InvenTree | Build - {{ build }} +{% endblock %} + +{% block content %} + +
+
+

Build Details

+

{{ build.title }}{% include "build_status.html" with build=build %}

+

Building {{ build.quantity }} × {{ build.part.full_name }}

+
+
+

+
+ +
+

+
+
+ +
+ +
+{% block details %} + +{% endblock %} + +
+ +{% include "modals.html" %} + +{% endblock %} + +{% block js_ready %} + + $("#build-edit").click(function () { + launchModalForm("{% url 'build-edit' build.id %}", + { + reload: true + }); + }); + + $("#build-cancel").click(function() { + launchModalForm("{% url 'build-cancel' build.id %}", + { + reload: true, + submit_text: "Cancel Build", + }); + }); + + $("#build-complete").on('click', function() { + launchModalForm( + "{% url 'build-complete' build.id %}", + { + reload: true, + submit_text: "Complete Build", + } + ); + }); + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index a46a146d77..99e4671d56 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -1,39 +1,11 @@ -{% extends "base.html" %} +{% extends "build/build_base.html" %} {% load static %} -{% block page_title %} -InvenTree | Build - {{ build }} -{% endblock %} +{% block details %} -{% block content %} +{% include "build/tabs.html" with tab='details' %} -
-
-

Build Details

-

{{ build.title }}{% include "build_status.html" with build=build %}

-

Building {{ build.quantity }} × {{ build.part.full_name }}

-
-
-

-
- -
-

-
-
+

Build Details

@@ -95,60 +67,4 @@ InvenTree | Build - {{ build }} {% endif %}
-{% if build.is_active %} -

Required Parts

- - - - - - - - - - - {% for item in build.required_parts %} - - - - - - - {% endfor %} - -
PartRequiredAvailableAllocated
{{ item.part.full_name }}{{ item.quantity }}{{ item.part.total_stock }}{{ item.allocated }}
- -{% endif %} - -{% include 'modals.html' %} - -{% endblock %} - -{% block js_ready %} -{{ block.super }} - $("#build-edit").click(function () { - launchModalForm("{% url 'build-edit' build.id %}", - { - reload: true - }); - }); - - $("#build-cancel").click(function() { - launchModalForm("{% url 'build-cancel' build.id %}", - { - reload: true, - submit_text: "Cancel Build", - }); - }); - - $("#build-complete").on('click', function() { - launchModalForm( - "{% url 'build-complete' build.id %}", - { - reload: true, - submit_text: "Complete Build", - } - ); - }); - {% endblock %} diff --git a/InvenTree/build/templates/build/required.html b/InvenTree/build/templates/build/required.html new file mode 100644 index 0000000000..f1dccde02e --- /dev/null +++ b/InvenTree/build/templates/build/required.html @@ -0,0 +1,36 @@ +{% extends "build/build_base.html" %} +{% load static %} + +{% block details %} + +{% include "build/tabs.html" with tab='required' %} + +

Required Parts

+ + + + + + + + + + + {% for item in build.required_parts %} + + + + + + + {% endfor %} + +
PartAvailableRequiredAllocated
+ + + + + {{ item.part.full_name }} + {{ item.part.total_stock }}{{ item.quantity }}{{ item.allocated }}
+ +{% endblock %} \ No newline at end of file diff --git a/InvenTree/build/templates/build/tabs.html b/InvenTree/build/templates/build/tabs.html new file mode 100644 index 0000000000..b30ba7762f --- /dev/null +++ b/InvenTree/build/templates/build/tabs.html @@ -0,0 +1,10 @@ + + +
\ No newline at end of file diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py index 3118bd6042..383e478494 100644 --- a/InvenTree/build/urls.py +++ b/InvenTree/build/urls.py @@ -24,6 +24,8 @@ build_detail_urls = [ url(r'^auto-allocate/?', views.BuildAutoAllocate.as_view(), name='build-auto-allocate'), url(r'^unallocate/', views.BuildUnallocate.as_view(), name='build-unallocate'), + url(r'^required/', views.BuildDetail.as_view(template_name='build/required.html'), name='build-required'), + url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'), ] From 2da3a022bfa6c62b4e3e80e520c3849ba8d81bd1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 17 May 2019 00:20:48 +1000 Subject: [PATCH 02/10] Add allocation tab --- InvenTree/build/templates/build/allocate.html | 11 +++++------ InvenTree/build/templates/build/allocation_item.html | 2 +- InvenTree/build/templates/build/tabs.html | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index 5b66ef6b57..ce84d86658 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "build/build_base.html" %} {% load static %} {% load inventree_extras %} @@ -6,15 +6,14 @@ InvenTree | Allocate Parts {% endblock %} -{% block content %} +{% block details %} -

Allocate Parts for Build

+{% include "build/tabs.html" with tab='allocate' %} + +

Allocate Parts for Build

- -

{{ build.title }}

- {{ build.quantity }} x {{ build.part.lonname }}
diff --git a/InvenTree/build/templates/build/allocation_item.html b/InvenTree/build/templates/build/allocation_item.html index 94e9e043a2..96520008bb 100644 --- a/InvenTree/build/templates/build/allocation_item.html +++ b/InvenTree/build/templates/build/allocation_item.html @@ -9,7 +9,7 @@
- {{ item.sub_part.full_name }}
+ {{ item.sub_part.full_name }} {{ item.sub_part.description }}
{% endblock %} diff --git a/InvenTree/build/templates/build/tabs.html b/InvenTree/build/templates/build/tabs.html index b30ba7762f..c52309b132 100644 --- a/InvenTree/build/templates/build/tabs.html +++ b/InvenTree/build/templates/build/tabs.html @@ -5,6 +5,9 @@ Required + + Allocate +
\ No newline at end of file From 489d5de9c4adfe576449636e2583b271c85ca95d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 17 May 2019 00:23:08 +1000 Subject: [PATCH 03/10] UI tweaks --- InvenTree/build/templates/build/build_base.html | 3 --- InvenTree/build/templates/build/required.html | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index f790275d2e..608b29f156 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -18,9 +18,6 @@ InvenTree | Build - {{ build }}

diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index 99e4671d56..6b916d08bf 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -60,11 +60,13 @@ Completed{{ build.completion_date }}{% if build.completed_by %}{{ build.completed_by }}{% endif %} {% endif %} -{% if build.notes %} - - Notes{{ build.notes }} - -{% endif %} +{% if build.notes %} +
+
Notes
+
{{ build.notes }}
+
+{% endif %} + {% endblock %} From 34d1ef7d8d10cc767bfaaf4349bee456f9f8452d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 May 2019 09:44:16 +1000 Subject: [PATCH 07/10] Change label size for build status --- InvenTree/static/css/inventree.css | 8 ++++++++ InvenTree/templates/build_status.html | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css index bca4560edf..bd05faaafe 100644 --- a/InvenTree/static/css/inventree.css +++ b/InvenTree/static/css/inventree.css @@ -32,6 +32,14 @@ padding: 5px 10px; } +/* Extra label styles */ + +.label-large { + padding: 5px; + margin: 3px; + font-size: 100%; +} + /* Force select2 elements in modal forms to be full width */ .select-full-width { width: 100%; diff --git a/InvenTree/templates/build_status.html b/InvenTree/templates/build_status.html index 3fc5f6086c..793e3ea231 100644 --- a/InvenTree/templates/build_status.html +++ b/InvenTree/templates/build_status.html @@ -1,11 +1,11 @@ {% if build.status == build.PENDING %} - + {% elif build.status == build.ALLOCATED %} - + {% elif build.status == build.CANCELLED %} - + {% elif build.status == build.COMPLETE %} - + {% endif %} {{ build.get_status_display }} \ No newline at end of file From a95e77c429ae58ab5b5c8d9b0d37b9c0742b8578 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 May 2019 12:17:57 +1000 Subject: [PATCH 08/10] Pre-fill allocation count --- InvenTree/build/templates/build/allocation_item.html | 2 +- InvenTree/part/templatetags/inventree_extras.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/InvenTree/build/templates/build/allocation_item.html b/InvenTree/build/templates/build/allocation_item.html index 96520008bb..f5af9ef6f4 100644 --- a/InvenTree/build/templates/build/allocation_item.html +++ b/InvenTree/build/templates/build/allocation_item.html @@ -25,7 +25,7 @@ Allocated:
- 0 + {% part_allocation_count build item.sub_part %}
diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index c06854227c..b17c5bf9e8 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -14,6 +14,13 @@ def multiply(x, y, *args, **kwargs): return x * y +@register.simple_tag() +def part_allocation_count(build, part, *args, **kwargs): + """ Return the total number of allocated to """ + + return build.getAllocatedQuantity(part) + + @register.simple_tag() def inventree_version(*args, **kwargs): """ Return InvenTree version string """ From 04420b7f6b3e1d01b90e9cae0eae89fc19a6712e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 May 2019 13:06:19 +1000 Subject: [PATCH 09/10] Improve display of allocation page --- InvenTree/build/templates/build/allocate.html | 15 +++++++++++++ .../templates/build/allocation_item.html | 21 ++++++++----------- InvenTree/static/css/inventree.css | 16 +++++++++----- InvenTree/templates/collapse.html | 2 +- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index ce84d86658..6d7017bcf2 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -24,6 +24,21 @@ InvenTree | Allocate Parts

+
+
+

Part

+
+
+

Available

+
+
+

Required

+
+
+

Allocated

+
+
+ {% for bom_item in bom_items.all %} {% include "build/allocation_item.html" with item=bom_item build=build collapse_id=bom_item.id %} {% endfor %} diff --git a/InvenTree/build/templates/build/allocation_item.html b/InvenTree/build/templates/build/allocation_item.html index f5af9ef6f4..920012e953 100644 --- a/InvenTree/build/templates/build/allocation_item.html +++ b/InvenTree/build/templates/build/allocation_item.html @@ -3,6 +3,8 @@ {% load static %} {% load inventree_extras %} +{% block collapse_panel_setup %}class='panel part-allocation' id='allocation-panel-{{ item.sub_part.id }}'{% endblock %} + {% block collapse_title %}
@@ -15,21 +17,16 @@ {% endblock %} {% block collapse_heading %} -
- Required: -
-
- {% multiply build.quantity item.quantity %} -
-
- Allocated: -
-
- {% part_allocation_count build item.sub_part %} +
+ {{ item.sub_part.available_stock }}
+ {% multiply build.quantity item.quantity %} +
+
+ {% part_allocation_count build item.sub_part %}
- +
{% endblock %} diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css index bd05faaafe..59e7899891 100644 --- a/InvenTree/static/css/inventree.css +++ b/InvenTree/static/css/inventree.css @@ -14,7 +14,6 @@ color: #ffcc00; } - /* CSS overrides for treeview */ .expand-icon { font-size: 11px; @@ -277,11 +276,12 @@ } .panel-group .panel { - border-radius: 8px; + border-radius: 2px; } .panel-heading { padding: 5px 10px; + background-color: #fafafa; } .float-right { @@ -299,16 +299,22 @@ transform: translate(-50%, -50%); } +.part-allocation { + padding: 3px 10px; + border: 1px solid #ccc; + border-radius: 2px; +} + .part-allocation-pass { - background: #dbf0db; + background-color: #dbf0db; } .part-allocation-underallocated { - background: #f0dbdb; + background-color: #f0dbdb; } .part-allocation-overallocated { - background: #ccf5ff; + background-color: #ccf5ff; } .glyphicon-refresh-animate { diff --git a/InvenTree/templates/collapse.html b/InvenTree/templates/collapse.html index 776c9cee35..5624f34094 100644 --- a/InvenTree/templates/collapse.html +++ b/InvenTree/templates/collapse.html @@ -2,7 +2,7 @@ {% endblock %}
-
+
From 001dacc14eb6e65ac823cefce79789e30568f845 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 May 2019 13:24:15 +1000 Subject: [PATCH 10/10] Display 'no stock available' warning --- .../templates/build/create_build_item.html | 9 ++++++++ InvenTree/build/views.py | 23 +++++++++++++++++-- InvenTree/static/script/inventree/build.js | 2 +- InvenTree/templates/modal_form.html | 4 ++-- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 InvenTree/build/templates/build/create_build_item.html diff --git a/InvenTree/build/templates/build/create_build_item.html b/InvenTree/build/templates/build/create_build_item.html new file mode 100644 index 0000000000..c08b987d36 --- /dev/null +++ b/InvenTree/build/templates/build/create_build_item.html @@ -0,0 +1,9 @@ +{% extends "modal_form.html" %} + +{% block pre_form_content %} +{% if no_stock %} + +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 7cef486d55..6f19c67754 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -355,9 +355,25 @@ class BuildItemCreate(AjaxCreateView): model = BuildItem form_class = forms.EditBuildItemForm - ajax_template_name = 'modal_form.html' + ajax_template_name = 'build/create_build_item.html' ajax_form_title = 'Allocate new Part' + part = None + available_stock = None + + def get_context_data(self): + ctx = super(AjaxCreateView, self).get_context_data() + + if self.part: + ctx['part'] = self.part + + if self.available_stock: + ctx['stock'] = self.available_stock + else: + ctx['no_stock'] = True + + return ctx + def get_form(self): """ Create Form for making / editing new Part object """ @@ -375,7 +391,7 @@ class BuildItemCreate(AjaxCreateView): if part_id: try: - Part.objects.get(pk=part_id) + self.part = Part.objects.get(pk=part_id) query = form.fields['stock_item'].queryset @@ -399,6 +415,8 @@ class BuildItemCreate(AjaxCreateView): form.fields['stock_item'].queryset = query stocks = query.all() + self.available_stock = stocks + # If there is only one item selected, select it if len(stocks) == 1: form.fields['stock_item'].initial = stocks[0].id @@ -408,6 +426,7 @@ class BuildItemCreate(AjaxCreateView): pass except Part.DoesNotExist: + self.part = None pass return form diff --git a/InvenTree/static/script/inventree/build.js b/InvenTree/static/script/inventree/build.js index c982cc254c..e3d1238e5e 100644 --- a/InvenTree/static/script/inventree/build.js +++ b/InvenTree/static/script/inventree/build.js @@ -56,7 +56,7 @@ function loadAllocationTable(table, part_id, part, url, required, button) { launchModalForm(button.attr('url'), { success: function() { table.bootstrapTable('refresh'); - } + }, }); }); diff --git a/InvenTree/templates/modal_form.html b/InvenTree/templates/modal_form.html index 1a99fc09ff..1f5482f8d6 100644 --- a/InvenTree/templates/modal_form.html +++ b/InvenTree/templates/modal_form.html @@ -5,13 +5,13 @@
{% endif %} {% if form.pre_form_warning %} -