mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-11 07:24:15 +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:
@ -360,7 +360,7 @@ class Part(MPTTModel):
|
||||
# And recursively check too
|
||||
item.sub_part.checkAddToBOM(parent)
|
||||
|
||||
def checkIfSerialNumberExists(self, sn):
|
||||
def checkIfSerialNumberExists(self, sn, exclude_self=False):
|
||||
"""
|
||||
Check if a serial number exists for this Part.
|
||||
|
||||
@ -369,10 +369,28 @@ class Part(MPTTModel):
|
||||
"""
|
||||
|
||||
parts = Part.objects.filter(tree_id=self.tree_id)
|
||||
|
||||
stock = StockModels.StockItem.objects.filter(part__in=parts, serial=sn)
|
||||
|
||||
if exclude_self:
|
||||
stock = stock.exclude(pk=self.pk)
|
||||
|
||||
return stock.exists()
|
||||
|
||||
def find_conflicting_serial_numbers(self, serials):
|
||||
"""
|
||||
For a provided list of serials, return a list of those which are conflicting.
|
||||
"""
|
||||
|
||||
conflicts = []
|
||||
|
||||
for serial in serials:
|
||||
if self.checkIfSerialNumberExists(serial, exclude_self=True):
|
||||
conflicts.append(serial)
|
||||
|
||||
return conflicts
|
||||
|
||||
|
||||
def getLatestSerialNumber(self):
|
||||
"""
|
||||
Return the "latest" serial number for this Part.
|
||||
|
Reference in New Issue
Block a user