mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #666 from SchrodingersGat/build-allocation
Build allocation fix
This commit is contained in:
commit
b2cb41f879
@ -9,7 +9,7 @@
|
|||||||
<h4>{% trans "Build Outputs" %}</h4>
|
<h4>{% trans "Build Outputs" %}</h4>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
{% include "stock_table.html" %}
|
{% include "stock_table.html" with read_only=True %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ from django_cleanup import cleanup
|
|||||||
|
|
||||||
from mptt.models import TreeForeignKey
|
from mptt.models import TreeForeignKey
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from fuzzywuzzy import fuzz
|
from fuzzywuzzy import fuzz
|
||||||
import hashlib
|
import hashlib
|
||||||
@ -1208,6 +1209,9 @@ class BomItem(models.Model):
|
|||||||
if percent < 0:
|
if percent < 0:
|
||||||
percent = 0
|
percent = 0
|
||||||
|
|
||||||
|
# Must be represented as a decimal
|
||||||
|
percent = Decimal(percent)
|
||||||
|
|
||||||
return int(percent * quantity)
|
return int(percent * quantity)
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -43,3 +43,55 @@ class BomItemTest(TestCase):
|
|||||||
# A validation error should be raised here
|
# A validation error should be raised here
|
||||||
item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7)
|
item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7)
|
||||||
item.clean()
|
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)
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
<div id='button-toolbar'>
|
<div id='button-toolbar'>
|
||||||
<div class='button-toolbar container-fluid' style='float: right;'>
|
<div class='button-toolbar container-fluid' style='float: right;'>
|
||||||
<button class='btn btn-default' id='stock-export' title='Export Stock Information'>{% trans "Export" %}</button>
|
<button class='btn btn-default' id='stock-export' title='Export Stock Information'>{% trans "Export" %}</button>
|
||||||
|
{% if read_only %}
|
||||||
|
{% else %}
|
||||||
<button class="btn btn-success" id='item-create'>{% trans "New Stock Item" %}</button>
|
<button class="btn btn-success" id='item-create'>{% trans "New Stock Item" %}</button>
|
||||||
<div class="dropdown" style='float: right;'>
|
<div class="dropdown" style='float: right;'>
|
||||||
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{% trans "Options" %}<span class="caret"></span></button>
|
<button id='stock-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{% trans "Options" %}<span class="caret"></span></button>
|
||||||
@ -15,6 +17,7 @@
|
|||||||
<li><a href='#' id='multi-item-delete' title='Delete selected items'>{% trans "Delete Stock" %}</a></li>
|
<li><a href='#' id='multi-item-delete' title='Delete selected items'>{% trans "Delete Stock" %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user