mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
[#2885] Support multiple '~' placeholders in serial numbers
This commit is contained in:
parent
e9500e4981
commit
8077469a3f
@ -427,8 +427,9 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
|
||||
serials = serials.strip()
|
||||
|
||||
# fill in the next serial number into the serial
|
||||
if '~' in serials:
|
||||
serials = serials.replace('~', str(next_number))
|
||||
while '~' in serials:
|
||||
serials = serials.replace('~', str(next_number), 1)
|
||||
next_number += 1
|
||||
|
||||
# Split input string by whitespace or comma (,) characters
|
||||
groups = re.split("[\s,]+", serials)
|
||||
|
@ -252,6 +252,11 @@ class TestSerialNumberExtraction(TestCase):
|
||||
sn = e("1, 2, 3, 4, 5", 5, 1)
|
||||
self.assertEqual(len(sn), 5)
|
||||
|
||||
# Test multiple placeholders
|
||||
sn = e("1 2 ~ ~ ~", 5, 3)
|
||||
self.assertEqual(len(sn), 5)
|
||||
self.assertEqual(sn, [1, 2, 3, 4, 5])
|
||||
|
||||
sn = e("1-5, 10-15", 11, 1)
|
||||
self.assertIn(3, sn)
|
||||
self.assertIn(13, sn)
|
||||
|
Loading…
Reference in New Issue
Block a user