mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Integer value required for trackable bom item
This commit is contained in:
parent
8537dc2a85
commit
68b9a690f2
@ -1339,6 +1339,11 @@ class BomItem(models.Model):
|
||||
checksum: Validation checksum for the particular BOM line item
|
||||
"""
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
self.clean()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('bom-item-detail', kwargs={'pk': self.id})
|
||||
|
||||
@ -1431,6 +1436,16 @@ class BomItem(models.Model):
|
||||
- A part cannot refer to a part which refers to it
|
||||
"""
|
||||
|
||||
# If the sub_part is 'trackable' then the 'quantity' field must be an integer
|
||||
try:
|
||||
if self.sub_part.trackable:
|
||||
if not self.quantity == int(self.quantity):
|
||||
raise ValidationError({
|
||||
"quantity": _("Quantity must be integer value for trackable parts")
|
||||
})
|
||||
except Part.DoesNotExist:
|
||||
pass
|
||||
|
||||
# A part cannot refer to itself in its BOM
|
||||
try:
|
||||
if self.sub_part is not None and self.part is not None:
|
||||
|
@ -44,6 +44,20 @@ class BomItemTest(TestCase):
|
||||
item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7)
|
||||
item.clean()
|
||||
|
||||
def test_integer_quantity(self):
|
||||
"""
|
||||
Test integer validation for BomItem
|
||||
"""
|
||||
|
||||
p = Part.objects.create(name="test", description="d", component=True, trackable=True)
|
||||
|
||||
# Creation of a BOMItem with a non-integer quantity of a trackable Part should fail
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
BomItem.objects.create(part=self.bob, sub_part=p, quantity=21.7)
|
||||
|
||||
# But with an integer quantity, should be fine
|
||||
BomItem.objects.create(part=self.bob, sub_part=p, quantity=21)
|
||||
|
||||
def test_overage(self):
|
||||
""" Test that BOM line overages are calculated correctly """
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user