mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
[#2885] Support partial sequences in serial nos ('1, 2, 3+')
This commit is contained in:
parent
8077469a3f
commit
1dba9f66fb
@ -439,6 +439,12 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
|
||||
|
||||
# Helper function to check for duplicated numbers
|
||||
def add_sn(sn):
|
||||
# Attempt integer conversion first, so numerical strings are never stored
|
||||
try:
|
||||
sn = int(sn)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if sn in numbers:
|
||||
errors.append(_('Duplicate serial: {sn}').format(sn=sn))
|
||||
else:
|
||||
@ -496,7 +502,7 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
|
||||
|
||||
# case 1
|
||||
else:
|
||||
end = start + expected_quantity
|
||||
end = start + (expected_quantity - len(numbers))
|
||||
|
||||
for n in range(start, end):
|
||||
add_sn(n)
|
||||
@ -506,13 +512,7 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
|
||||
|
||||
# At this point, we assume that the "group" is just a single serial value
|
||||
elif group:
|
||||
|
||||
try:
|
||||
# First attempt to add as an integer value
|
||||
add_sn(int(group))
|
||||
except (ValueError):
|
||||
# As a backup, add as a string value
|
||||
add_sn(group)
|
||||
add_sn(group)
|
||||
|
||||
# No valid input group detected
|
||||
else:
|
||||
|
@ -252,6 +252,11 @@ class TestSerialNumberExtraction(TestCase):
|
||||
sn = e("1, 2, 3, 4, 5", 5, 1)
|
||||
self.assertEqual(len(sn), 5)
|
||||
|
||||
# Test partially specifying serials
|
||||
sn = e("1, 2, 4+", 5, 1)
|
||||
self.assertEqual(len(sn), 5)
|
||||
self.assertEqual(sn, [1, 2, 4, 5, 6])
|
||||
|
||||
# Test multiple placeholders
|
||||
sn = e("1 2 ~ ~ ~", 5, 3)
|
||||
self.assertEqual(len(sn), 5)
|
||||
|
Loading…
Reference in New Issue
Block a user