mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Critical bug fix: Check if serial numbers already exist when creating new StockItem
This commit is contained in:
parent
f485bc7d53
commit
3226a1906f
@ -528,11 +528,34 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
serial_numbers = data.get('serial_numbers', '')
|
serial_numbers = data.get('serial_numbers', '')
|
||||||
|
|
||||||
# Assign serial numbers for a trackable part
|
# Assign serial numbers for a trackable part
|
||||||
if serial_numbers and part.trackable:
|
if serial_numbers:
|
||||||
|
|
||||||
|
if not part.trackable:
|
||||||
|
raise ValidationError({
|
||||||
|
'serial_numbers': [_("Serial numbers cannot be supplied for a non-trackable part")]
|
||||||
|
})
|
||||||
|
|
||||||
# If serial numbers are specified, check that they match!
|
# If serial numbers are specified, check that they match!
|
||||||
try:
|
try:
|
||||||
serials = extract_serial_numbers(serial_numbers, quantity, part.getLatestSerialNumberInt())
|
serials = extract_serial_numbers(serial_numbers, quantity, part.getLatestSerialNumberInt())
|
||||||
|
|
||||||
|
# Determine if any of the specified serial numbers already exist!
|
||||||
|
existing = []
|
||||||
|
|
||||||
|
for serial in serials:
|
||||||
|
if part.checkIfSerialNumberExists(serial):
|
||||||
|
existing.append(serial)
|
||||||
|
|
||||||
|
if len(existing) > 0:
|
||||||
|
|
||||||
|
msg = _("The following serial numbers already exist")
|
||||||
|
msg += " : "
|
||||||
|
msg += ",".join([str(e) for e in existing])
|
||||||
|
|
||||||
|
raise ValidationError({
|
||||||
|
'serial_numbers': [msg],
|
||||||
|
})
|
||||||
|
|
||||||
except DjangoValidationError as e:
|
except DjangoValidationError as e:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'quantity': e.messages,
|
'quantity': e.messages,
|
||||||
|
Loading…
Reference in New Issue
Block a user