diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 68f42bab87..675898e3d0 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -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 diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index 51e5527535..13f9198d92 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -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)