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:
@@ -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:
|
||||
|
Reference in New Issue
Block a user