From 33ffa2f75fd9cd8809cd8f4126ba6fe5d6cbd49f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 18 Mar 2020 20:37:25 +1100 Subject: [PATCH 1/3] Add option to make stock-table read-only - Default table is not read-only --- InvenTree/build/templates/build/build_output.html | 2 +- InvenTree/templates/stock_table.html | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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/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 %}
From 3b9f57fc803988e3c8a52840a28a65827f58e943 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 18 Mar 2020 20:44:45 +1100 Subject: [PATCH 2/3] Bug fix - Multiplying float by decimal - Overage percentage now uses explicit decimal multiplication --- InvenTree/part/models.py | 4 ++++ 1 file changed, 4 insertions(+) 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: From c04aa1bff7274e9ef81008b899fd1aea16687286 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 18 Mar 2020 21:04:37 +1100 Subject: [PATCH 3/3] Increase unit testing for BOM item model --- InvenTree/part/test_bom_item.py | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) 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)