mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
Improve validation logic for StockItem
- Allow tracked items to exist without a serial number (e.g. non-serialized tracked items)
This commit is contained in:
parent
42e1370e92
commit
94c0102742
@ -118,11 +118,12 @@ class EditStockItemForm(HelperForm):
|
|||||||
|
|
||||||
fields = [
|
fields = [
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
|
'serial',
|
||||||
'batch',
|
'batch',
|
||||||
'delete_on_deplete',
|
|
||||||
'status',
|
'status',
|
||||||
'notes',
|
'notes',
|
||||||
'URL',
|
'URL',
|
||||||
|
'delete_on_deplete',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,20 +190,21 @@ class StockItem(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
if self.part is not None:
|
if self.part is not None:
|
||||||
# A trackable part must have a serial number
|
# A part with a serial number MUST have the quantity set to 1
|
||||||
if self.part.trackable:
|
if self.serial is not None:
|
||||||
if not self.serial:
|
if self.quantity > 1:
|
||||||
raise ValidationError({'serial': _('Serial number must be set for trackable items')})
|
raise ValidationError({
|
||||||
|
'quantity': _('Quantity must be 1 for item with a serial number'),
|
||||||
|
'serial': _('Serial number cannot be set if quantity greater than 1')
|
||||||
|
})
|
||||||
|
|
||||||
|
if self.quantity == 0:
|
||||||
|
raise ValidationError({
|
||||||
|
'quantity': _('Quantity must be 1 for item with a serial number')
|
||||||
|
})
|
||||||
|
|
||||||
if self.delete_on_deplete:
|
if self.delete_on_deplete:
|
||||||
raise ValidationError({'delete_on_deplete': _("Must be set to False for trackable items")})
|
raise ValidationError({'delete_on_deplete': _("Must be set to False for item with a serial number")})
|
||||||
|
|
||||||
# Serial number cannot be set for items with quantity greater than 1
|
|
||||||
if not self.quantity == 1:
|
|
||||||
raise ValidationError({
|
|
||||||
'quantity': _("Quantity must be set to 1 for item with a serial number"),
|
|
||||||
'serial': _("Serial number cannot be set if quantity > 1")
|
|
||||||
})
|
|
||||||
|
|
||||||
# A template part cannot be instantiated as a StockItem
|
# A template part cannot be instantiated as a StockItem
|
||||||
if self.part.is_template:
|
if self.part.is_template:
|
||||||
@ -422,7 +423,7 @@ class StockItem(models.Model):
|
|||||||
if location is None:
|
if location is None:
|
||||||
# TODO - Raise appropriate error (cannot move to blank location)
|
# TODO - Raise appropriate error (cannot move to blank location)
|
||||||
return False
|
return False
|
||||||
elif self.location and (location.pk == self.location.pk):
|
elif self.location and (location.pk == self.location.pk) and (quantity == self.quantity):
|
||||||
# TODO - Raise appropriate error (cannot move to same location)
|
# TODO - Raise appropriate error (cannot move to same location)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user