mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-28 14:25:56 +00:00
Refactor how form errors are handled
- Use form.add_error (as the django gods intended)
This commit is contained in:
@@ -814,14 +814,11 @@ class StockItem(MPTTModel):
|
||||
raise ValidationError({"quantity": _("Quantity does not match serial numbers")})
|
||||
|
||||
# Test if each of the serial numbers are valid
|
||||
existing = []
|
||||
|
||||
for serial in serials:
|
||||
if self.part.checkIfSerialNumberExists(serial):
|
||||
existing.append(serial)
|
||||
existing = self.part.find_conflicting_serial_numbers(serials)
|
||||
|
||||
if len(existing) > 0:
|
||||
raise ValidationError({"serial_numbers": _("Serial numbers already exist: ") + str(existing)})
|
||||
exists = ','.join([str(x) for x in existing])
|
||||
raise ValidationError({"serial_numbers": _("Serial numbers already exist") + ': ' + exists})
|
||||
|
||||
# Create a new stock item for each unique serial number
|
||||
for serial in serials:
|
||||
|
Reference in New Issue
Block a user