mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Catch BuildItem errors in clean()
This commit is contained in:
parent
fbd5a2a270
commit
6961d1ec68
@ -147,15 +147,25 @@ class BuildItem(models.Model):
|
||||
The following checks are performed:
|
||||
|
||||
- StockItem.part must be in the BOM of the Part object referenced by Build
|
||||
- Allocation quantity cannot exceed available quantity
|
||||
"""
|
||||
|
||||
super(BuildItem, self).clean()
|
||||
|
||||
errors = {}
|
||||
|
||||
if self.stock_item is not None and self.stock_item.part is not None:
|
||||
if self.stock_item.part not in self.build.part.required_parts():
|
||||
print('stock_item:', self.stock_item.part)
|
||||
for p in self.build.part.bom_items.all():
|
||||
print('bom_part:', p)
|
||||
raise ValidationError(
|
||||
{'stock_item': _("Selected stock item not found in BOM for part '{p}'".format(p=str(self.build.part)))}
|
||||
)
|
||||
errors['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,
|
||||
|
Loading…
Reference in New Issue
Block a user