From 5ae7ca71d704b47d71accee1dcf8e7f12faad294 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 12 Feb 2020 08:12:26 +1100 Subject: [PATCH] Improve number rendering of build allocation page --- InvenTree/InvenTree/static/script/inventree/build.js | 11 +++++++---- InvenTree/build/models.py | 3 ++- InvenTree/build/templates/build/allocation_item.html | 2 +- InvenTree/part/templatetags/inventree_extras.py | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/build.js b/InvenTree/InvenTree/static/script/inventree/build.js index 0a9250ebb2..c80cc00252 100644 --- a/InvenTree/InvenTree/static/script/inventree/build.js +++ b/InvenTree/InvenTree/static/script/inventree/build.js @@ -27,21 +27,24 @@ function loadAllocationTable(table, part_id, part, url, required, button) { field: 'stock_item_detail', title: 'Stock Item', formatter: function(value, row, index, field) { - return '' + value.quantity + ' x ' + value.part_name + ' @ ' + value.location_name; + return '' + parseFloat(value.quantity) + ' x ' + value.part_name + ' @ ' + value.location_name; } }, { field: 'stock_item_detail.quantity', title: 'Available', + formatter: function(value, row, index, field) { + return parseFloat(value); + } }, { field: 'quantity', title: 'Allocated', formatter: function(value, row, index, field) { - var html = value; + var html = parseFloat(value); - var bEdit = ""; - var bDel = ""; + var bEdit = ""; + var bDel = ""; html += "
" + bEdit + bDel + "
"; diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index b625dde475..f9d3399eae 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -20,6 +20,7 @@ from markdownx.models import MarkdownxField from InvenTree.status_codes import BuildStatus from InvenTree.fields import InvenTreeURLField +from InvenTree.helpers import decimal2string from stock.models import StockItem from part.models import Part, BomItem @@ -42,7 +43,7 @@ class Build(models.Model): """ def __str__(self): - return "Build {q} x {part}".format(q=self.quantity, part=str(self.part)) + return "Build {q} x {part}".format(q=decimal2string(self.quantity), part=str(self.part)) def get_absolute_url(self): return reverse('build-detail', kwargs={'pk': self.id}) diff --git a/InvenTree/build/templates/build/allocation_item.html b/InvenTree/build/templates/build/allocation_item.html index 7339f7aff4..87b6ba1340 100644 --- a/InvenTree/build/templates/build/allocation_item.html +++ b/InvenTree/build/templates/build/allocation_item.html @@ -15,7 +15,7 @@ {% block collapse_heading %}
- {{ item.sub_part.total_stock }} + {% decimal item.sub_part.total_stock %}
{% multiply build.quantity item.quantity %} diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 0a111bfb0e..d508452e80 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -27,7 +27,7 @@ def inrange(n, *args, **kwargs): @register.simple_tag() def multiply(x, y, *args, **kwargs): """ Multiply two numbers together """ - return x * y + return decimal2string(x * y) @register.simple_tag() @@ -40,7 +40,7 @@ def add(x, y, *args, **kwargs): def part_allocation_count(build, part, *args, **kwargs): """ Return the total number of allocated to """ - return build.getAllocatedQuantity(part) + return decimal2string(build.getAllocatedQuantity(part)) @register.simple_tag()