2
0
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:
Oliver Walters
2020-10-28 23:33:33 +11:00
parent fb28204dfd
commit c533f59405
8 changed files with 80 additions and 65 deletions

View File

@@ -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: