diff --git a/InvenTree/build/templates/build/build_output.html b/InvenTree/build/templates/build/build_output.html index f35672bf79..e5a3e77e61 100644 --- a/InvenTree/build/templates/build/build_output.html +++ b/InvenTree/build/templates/build/build_output.html @@ -9,7 +9,7 @@

{% trans "Build Outputs" %}


-{% include "stock_table.html" %} +{% include "stock_table.html" with read_only=True %} {% endblock %} diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 59bcbe57b1..f305b51c4c 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -27,6 +27,7 @@ from django_cleanup import cleanup from mptt.models import TreeForeignKey +from decimal import Decimal from datetime import datetime from fuzzywuzzy import fuzz import hashlib @@ -1208,6 +1209,9 @@ class BomItem(models.Model): if percent < 0: percent = 0 + # Must be represented as a decimal + percent = Decimal(percent) + return int(percent * quantity) except ValueError: diff --git a/InvenTree/part/test_bom_item.py b/InvenTree/part/test_bom_item.py index e5d94744c0..95e1dbb2c7 100644 --- a/InvenTree/part/test_bom_item.py +++ b/InvenTree/part/test_bom_item.py @@ -43,3 +43,55 @@ class BomItemTest(TestCase): # A validation error should be raised here item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7) item.clean() + + def test_overage(self): + """ Test that BOM line overages are calculated correctly """ + + item = BomItem.objects.get(part=100, sub_part=50) + + q = 300 + + item.quantity = q + + # Test empty overage + n = item.get_overage_quantity(q) + self.assertEqual(n, 0) + + # Test improper overage + item.overage = 'asf234?' + n = item.get_overage_quantity(q) + self.assertEqual(n, 0) + + # Test absolute overage + item.overage = '3' + n = item.get_overage_quantity(q) + self.assertEqual(n, 3) + + # Test percentage-based overage + item.overage = '5.0 % ' + n = item.get_overage_quantity(q) + self.assertEqual(n, 15) + + # Calculate total required quantity + # Quantity = 300 (+ 5%) + # Get quantity required to build B = 10 + # Q * B = 3000 + 5% = 3150 + n = item.get_required_quantity(10) + + self.assertEqual(n, 3150) + + def test_item_hash(self): + """ Test BOM item hash encoding """ + + item = BomItem.objects.get(part=100, sub_part=50) + + h1 = item.get_item_hash() + + # Change data - the hash must change + item.quantity += 1 + + h2 = item.get_item_hash() + + item.validate_hash() + + self.assertNotEqual(h1, h2) diff --git a/InvenTree/templates/stock_table.html b/InvenTree/templates/stock_table.html index 31eaf30bb7..2d823c9510 100644 --- a/InvenTree/templates/stock_table.html +++ b/InvenTree/templates/stock_table.html @@ -3,6 +3,8 @@
+ {% if read_only %} + {% else %} + {% endif %}