Improve number rendering of build allocation page

This commit is contained in:
Oliver Walters 2020-02-12 08:12:26 +11:00
parent 564635c368
commit 5ae7ca71d7
4 changed files with 12 additions and 8 deletions

View File

@ -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 = "<button class='btn btn-primary item-edit-button btn-sm' type='button' title='Edit stock allocation' url='/build/item/" + row.pk + "/edit/'><span class='glyphicon glyphicon-small glyphicon-edit'></span></button>";
var bDel = "<button class='btn btn-danger item-del-button btn-sm' type='button' title='Delete stock allocation' url='/build/item/" + row.pk + "/delete/'><span class='glyphicon glyphicon-small glyphicon-trash'></span></button>";
var bEdit = "<button class='btn item-edit-button btn-sm' type='button' title='Edit stock allocation' url='/build/item/" + row.pk + "/edit/'><span class='glyphicon glyphicon-small glyphicon-edit'></span></button>";
var bDel = "<button class='btn item-del-button btn-sm' type='button' title='Delete stock allocation' url='/build/item/" + row.pk + "/delete/'><span class='glyphicon glyphicon-small glyphicon-trash'></span></button>";
html += "<div class='btn-group' style='float: right;'>" + bEdit + bDel + "</div>";

View File

@ -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})

View File

@ -15,7 +15,7 @@
{% block collapse_heading %}
<div class='col-sm-2'>
<b>{{ item.sub_part.total_stock }}</b>
<b>{% decimal item.sub_part.total_stock %}</b>
</div>
<div class='col-sm-2'>
<b>{% multiply build.quantity item.quantity %}</b>

View File

@ -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 <part> allocated to <build> """
return build.getAllocatedQuantity(part)
return decimal2string(build.getAllocatedQuantity(part))
@register.simple_tag()