2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-09 07:00:56 +00:00

also validate serial number

This commit is contained in:
Matthias
2021-12-02 12:11:09 +01:00
parent 29cd2ee9bd
commit b0fb5657e8
2 changed files with 8 additions and 12 deletions

View File

@ -39,6 +39,7 @@ import label.models
from InvenTree.status_codes import StockStatus, StockHistoryCode
from InvenTree.models import InvenTreeTree, InvenTreeAttachment
from InvenTree.fields import InvenTreeModelMoneyField, InvenTreeURLField
from InvenTree.serializers import extract_int
from users.models import Owner
@ -236,17 +237,7 @@ class StockItem(MPTTModel):
serial_int = 0
if serial is not None:
serial = str(serial)
# Look at the start of the string - can it be "integerized"?
result = re.match(r'^(\d+)', serial)
if result and len(result.groups()) == 1:
try:
serial_int = int(result.groups()[0])
except:
serial_int = 0
serial_int = extract_int(str(serial))
self.serial_int = serial_int