mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-13 08:21:26 +00:00
BOM serializer now validates against model
- Need to call instance.clean() - https://stackoverflow.com/questions/40697648/django-dry-model-form-serializer-validation
This commit is contained in:
@ -359,11 +359,12 @@ class BomItem(models.Model):
|
||||
|
||||
# A part cannot refer to itself in its BOM
|
||||
if self.part == self.sub_part:
|
||||
raise ValidationError(_('A part cannot contain itself as a BOM item'))
|
||||
raise ValidationError({'sub_part': _('Part cannot be added to its own Bill of Materials')})
|
||||
|
||||
# Test for simple recursion
|
||||
for item in self.sub_part.bom_items.all():
|
||||
if self.part == item.sub_part:
|
||||
raise ValidationError(_("Part '{p1}' is used in BOM for '{p2}' (recursive)".format(p1=str(self.part), p2=str(self.sub_part))))
|
||||
raise ValidationError({'sub_part': _("Part '{p1}' is used in BOM for '{p2}' (recursive)".format(p1=str(self.part), p2=str(self.sub_part)))})
|
||||
|
||||
class Meta:
|
||||
verbose_name = "BOM Item"
|
||||
|
Reference in New Issue
Block a user