mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix for BomItem clean function
Handle the case where the sub_part does not exist
This commit is contained in:
parent
73259c0bcb
commit
af9b88de11
@ -1086,7 +1086,7 @@ class Part(MPTTModel):
|
|||||||
for bom_item in self.bom_items.all().select_related('sub_part'):
|
for bom_item in self.bom_items.all().select_related('sub_part'):
|
||||||
|
|
||||||
sub_part = bom_item.sub_part
|
sub_part = bom_item.sub_part
|
||||||
|
|
||||||
if sub_part not in parts:
|
if sub_part not in parts:
|
||||||
|
|
||||||
parts.add(sub_part)
|
parts.add(sub_part)
|
||||||
@ -1885,25 +1885,28 @@ class BomItem(models.Model):
|
|||||||
- If the "sub_part" is trackable, then the "part" must be trackable too!
|
- If the "sub_part" is trackable, then the "part" must be trackable too!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# If the sub_part is 'trackable' then the 'quantity' field must be an integer
|
|
||||||
try:
|
try:
|
||||||
if self.sub_part.trackable:
|
# Check for circular BOM references
|
||||||
if not self.quantity == int(self.quantity):
|
if self.sub_part:
|
||||||
raise ValidationError({
|
self.sub_part.checkAddToBOM(self.part)
|
||||||
"quantity": _("Quantity must be integer value for trackable parts")
|
|
||||||
})
|
# If the sub_part is 'trackable' then the 'quantity' field must be an integer
|
||||||
|
if self.sub_part.trackable:
|
||||||
# Force the upstream part to be trackable if the sub_part is trackable
|
if not self.quantity == int(self.quantity):
|
||||||
if not self.part.trackable:
|
raise ValidationError({
|
||||||
self.part.trackable = True
|
"quantity": _("Quantity must be integer value for trackable parts")
|
||||||
self.part.clean()
|
})
|
||||||
self.part.save()
|
|
||||||
|
|
||||||
|
# Force the upstream part to be trackable if the sub_part is trackable
|
||||||
|
if not self.part.trackable:
|
||||||
|
self.part.trackable = True
|
||||||
|
self.part.clean()
|
||||||
|
self.part.save()
|
||||||
|
else:
|
||||||
|
raise ValidationError({'sub_part': _('Sub part must be specified')})
|
||||||
except Part.DoesNotExist:
|
except Part.DoesNotExist:
|
||||||
pass
|
raise ValidationError({'sub_part': _('Sub part must be specified')})
|
||||||
|
|
||||||
# Check for circular BOM references
|
|
||||||
self.sub_part.checkAddToBOM(self.part)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("BOM Item")
|
verbose_name = _("BOM Item")
|
||||||
|
Loading…
Reference in New Issue
Block a user