2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Require either serial or batch number to be set for trackable part

This commit is contained in:
Oliver Walters
2020-10-27 22:00:38 +11:00
parent 54d5d2899e
commit 646fe40950
2 changed files with 15 additions and 8 deletions

View File

@ -200,6 +200,13 @@ class StockItem(MPTTModel):
super(StockItem, self).validate_unique(exclude)
# If the part is trackable, either serial number or batch number must be set
if self.part.trackable:
if not self.serial and not self.batch:
msg = _('Serial or batch number must be specified for trackable stock')
raise ValidationError(msg)
# If the serial number is set, make sure it is not a duplicate
if self.serial is not None:
# Query to look for duplicate serial numbers
parts = PartModels.Part.objects.filter(tree_id=self.part.tree_id)