mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix validation of duplicate IPN
- Duplicate IPN check does not apply if an empty IPN value is set - Note that "if x" is a more pythonic test than "if x not in [None, '']"
This commit is contained in:
parent
42f0628a48
commit
9a9ed5f192
@ -777,7 +777,8 @@ class Part(MPTTModel):
|
|||||||
# User can decide whether duplicate IPN (Internal Part Number) values are allowed
|
# User can decide whether duplicate IPN (Internal Part Number) values are allowed
|
||||||
allow_duplicate_ipn = common.models.InvenTreeSetting.get_setting('PART_ALLOW_DUPLICATE_IPN')
|
allow_duplicate_ipn = common.models.InvenTreeSetting.get_setting('PART_ALLOW_DUPLICATE_IPN')
|
||||||
|
|
||||||
if self.IPN is not None and not allow_duplicate_ipn:
|
# Raise an error if an IPN is set, and it is a duplicate
|
||||||
|
if self.IPN and not allow_duplicate_ipn:
|
||||||
parts = Part.objects.filter(IPN__iexact=self.IPN)
|
parts = Part.objects.filter(IPN__iexact=self.IPN)
|
||||||
parts = parts.exclude(pk=self.pk)
|
parts = parts.exclude(pk=self.pk)
|
||||||
|
|
||||||
@ -798,6 +799,10 @@ class Part(MPTTModel):
|
|||||||
|
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
|
# Strip IPN field
|
||||||
|
if self.IPN:
|
||||||
|
self.IPN = self.IPN.strip()
|
||||||
|
|
||||||
if self.trackable:
|
if self.trackable:
|
||||||
for part in self.get_used_in().all():
|
for part in self.get_used_in().all():
|
||||||
|
|
||||||
|
@ -453,10 +453,12 @@ class StockItem(MPTTModel):
|
|||||||
|
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.serial is not None and type(self.serial) is str:
|
# Strip serial number field
|
||||||
|
if self.serial:
|
||||||
self.serial = self.serial.strip()
|
self.serial = self.serial.strip()
|
||||||
|
|
||||||
if self.batch is not None and type(self.batch) is str:
|
# Strip batch code field
|
||||||
|
if self.batch:
|
||||||
self.batch = self.batch.strip()
|
self.batch = self.batch.strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user