[#2885] Support hyphens in serials when correct no of serials supplied

This commit is contained in:
Paul R 2022-04-28 10:38:34 +01:00
parent b08efa4de7
commit 82b32fe30e
2 changed files with 16 additions and 1 deletions

View File

@ -458,8 +458,18 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
if len(serials) == 0:
raise ValidationError([_("Empty serial number string")])
for group in groups:
# If the user has supplied the correct number of serials, don't process them for groups
# just add them so any duplicates (or future validations) are checked
if len(groups) == expected_quantity:
for group in groups:
add_sn(group)
if len(errors) > 0:
raise ValidationError(errors)
return numbers
for group in groups:
group = group.strip()
# Hyphen indicates a range of numbers

View File

@ -257,6 +257,11 @@ class TestSerialNumberExtraction(TestCase):
self.assertEqual(len(sn), 5)
self.assertEqual(sn, [1, 2, 4, 5, 6])
# Test groups are not interpolated if enough serials are supplied
sn = e("1, 2, 3, AF5-69H, 5", 5, 1)
self.assertEqual(len(sn), 5)
self.assertEqual(sn, [1, 2, 3, "AF5-69H", 5])
# Test groups are not interpolated with more than one hyphen in a word
sn = e("1, 2, TG-4SR-92, 4+", 5, 1)
self.assertEqual(len(sn), 5)