From 98109bb1a102dfff3aba560b7b99e3de1b454189 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 1 May 2019 22:12:09 +1000 Subject: [PATCH] Make build allocation much more intuiitive - Display current allocation + total allocation requirement - Color code results - Required custom 'multiply' template tag --- InvenTree/build/templates/build/allocate.html | 3 ++ .../templates/build/allocation_item.html | 16 +++++++++- InvenTree/build/templatetags/__init__.py | 0 .../build/templatetags/inventree_extras.py | 12 +++++++ InvenTree/static/css/inventree.css | 14 +++++++- InvenTree/static/script/inventree/build.js | 32 ++++++++++++++++++- 6 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 InvenTree/build/templatetags/__init__.py create mode 100644 InvenTree/build/templatetags/inventree_extras.py diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index 92d0e9bf7b..e9438d898f 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load static %} +{% load inventree_extras %} {% block content %} @@ -36,8 +37,10 @@ loadAllocationTable( $("#allocate-table-id-{{ bom_item.sub_part.id }}"), + {{ bom_item.sub_part.id }}, "{{ bom_item.sub_part.name }}", "{% url 'api-build-item-list' %}?build={{ build.id }}&part={{ bom_item.sub_part.id }}", + {% multiply build.quantity bom_item.quantity %}, $("#new-item-{{ bom_item.sub_part.id }}") ); diff --git a/InvenTree/build/templates/build/allocation_item.html b/InvenTree/build/templates/build/allocation_item.html index 271ae94e3a..9982457aca 100644 --- a/InvenTree/build/templates/build/allocation_item.html +++ b/InvenTree/build/templates/build/allocation_item.html @@ -1,3 +1,5 @@ +{% load inventree_extras %} +
@@ -7,7 +9,19 @@ {{ item.sub_part.name }}
-
+
+ Required: +
+
+ {% multiply build.quantity item.quantity %} +
+
+ Allocated: +
+
+ 0 +
+
diff --git a/InvenTree/build/templatetags/__init__.py b/InvenTree/build/templatetags/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/InvenTree/build/templatetags/inventree_extras.py b/InvenTree/build/templatetags/inventree_extras.py new file mode 100644 index 0000000000..cb8cd0d235 --- /dev/null +++ b/InvenTree/build/templatetags/inventree_extras.py @@ -0,0 +1,12 @@ +""" This module provides template tags for extra functionality +over and above the built-in Django tags. +""" + +from django import template + +register = template.Library() + + +@register.simple_tag() +def multiply(x, y, *args, **kwargs): + return x * y diff --git a/InvenTree/static/css/inventree.css b/InvenTree/static/css/inventree.css index f16ce3f038..0a1c34036b 100644 --- a/InvenTree/static/css/inventree.css +++ b/InvenTree/static/css/inventree.css @@ -139,4 +139,16 @@ top: 50%; left: 50%; transform: translate(-50%, -50%); -} \ No newline at end of file +} + +.part-allocation-pass { + background: #dbf0db; +} + +.part-allocation-underallocated { + background: #f0dbdb; +} + +.part-allocation-overallocated { + background: #ccf5ff; +} diff --git a/InvenTree/static/script/inventree/build.js b/InvenTree/static/script/inventree/build.js index 92fbf430f7..fd20af0743 100644 --- a/InvenTree/static/script/inventree/build.js +++ b/InvenTree/static/script/inventree/build.js @@ -1,4 +1,21 @@ -function loadAllocationTable(table, part, url, button) { +function updateAllocationTotal(id, count, required) { + + + $('#allocation-total-'+id).html(count); + + var el = $("#allocation-panel-" + id); + el.removeClass('part-allocation-pass part-allocation-underallocated part-allocation-overallocated'); + + if (count < required) { + el.addClass('part-allocation-underallocated'); + } else if (count > required) { + el.addClass('part-allocation-overallocated'); + } else { + el.addClass('part-allocation-pass'); + } +} + +function loadAllocationTable(table, part_id, part, url, required, button) { // Load the allocation table table.bootstrapTable({ @@ -39,6 +56,19 @@ function loadAllocationTable(table, part, url, button) { }); }); + table.on('load-success.bs.table', function(data) { + // Extract table data + var results = table.bootstrapTable('getData'); + + var count = 0; + + for (var i = 0; i < results.length; i++) { + count += results[i].quantity; + } + + updateAllocationTotal(part_id, count, required); + }); + // Button callbacks for editing and deleting the allocations table.on('click', '.item-edit-button', function() { var button = $(this);