2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-30 04:26:44 +00:00

Catch BuildItem errors in clean()

This commit is contained in:
Oliver Walters 2019-04-30 16:35:55 +10:00
parent fbd5a2a270
commit 6961d1ec68

View File

@ -147,15 +147,25 @@ class BuildItem(models.Model):
The following checks are performed: The following checks are performed:
- StockItem.part must be in the BOM of the Part object referenced by Build - StockItem.part must be in the BOM of the Part object referenced by Build
- Allocation quantity cannot exceed available quantity
""" """
super(BuildItem, self).clean()
if self.stock_item.part not in self.build.part.required_parts(): errors = {}
print('stock_item:', self.stock_item.part)
for p in self.build.part.bom_items.all(): if self.stock_item is not None and self.stock_item.part is not None:
print('bom_part:', p) if self.stock_item.part not in self.build.part.required_parts():
raise ValidationError( errors['stock_item'] = _("Selected stock item not found in BOM for part '{p}'".format(p=str(self.build.part)))
{'stock_item': _("Selected stock item not found in BOM for part '{p}'".format(p=str(self.build.part)))}
) if self.stock_item is not None and self.quantity > self.stock_item.quantity:
errors['quantity'] = _("Allocated quantity ({n}) must not exceed available quantity ({q})".format(
n=self.quantity,
q=self.stock_item.quantity
))
if len(errors) > 0:
raise ValidationError(errors)
build = models.ForeignKey( build = models.ForeignKey(
Build, Build,