From 8077469a3f5aa9f0ecb95d1994720328ae868bed Mon Sep 17 00:00:00 2001 From: Paul R Date: Thu, 28 Apr 2022 10:32:13 +0100 Subject: [PATCH] [#2885] Support multiple '~' placeholders in serial numbers --- InvenTree/InvenTree/helpers.py | 5 +++-- InvenTree/InvenTree/tests.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index c5a8ad4b67..b94383c874 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -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) diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index 669628bdea..11ca990b8e 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -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)