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

- When in doubt, refer to the django docs
- There was a *much* better way (thanks, form.add_error)!
- The anti-pattern was deleted, and lo, there was much rejoicing
- Some other refactoring too
This commit is contained in:
Oliver Walters
2020-10-28 23:33:33 +11:00
parent d06b4d7c9f
commit 091a9d9803
8 changed files with 112 additions and 88 deletions

View File

@@ -822,14 +822,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: