[#2885] Support multiple '~' placeholders in serial numbers

This commit is contained in:
Paul R 2022-04-28 10:32:13 +01:00
parent e9500e4981
commit 8077469a3f
2 changed files with 8 additions and 2 deletions

View File

@ -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)

View File

@ -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)