mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	[#2885] Don't interpolate serial groups if they are not numeric
This commit is contained in:
		@@ -466,7 +466,7 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
 | 
			
		||||
        if '-' in group:
 | 
			
		||||
            items = group.split('-')
 | 
			
		||||
 | 
			
		||||
            if len(items) == 2:
 | 
			
		||||
            if len(items) == 2 and all([i.isnumeric() for i in items]):
 | 
			
		||||
                a = items[0].strip()
 | 
			
		||||
                b = items[1].strip()
 | 
			
		||||
 | 
			
		||||
@@ -484,7 +484,8 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
 | 
			
		||||
                    errors.append(_("Invalid group: {g}").format(g=group))
 | 
			
		||||
                    continue
 | 
			
		||||
            else:
 | 
			
		||||
                errors.append(_("Invalid group: {g}").format(g=group))
 | 
			
		||||
                # More than 2 hyphens or non-numeric group so add without interpolating
 | 
			
		||||
                add_sn(group)
 | 
			
		||||
 | 
			
		||||
        # plus signals either
 | 
			
		||||
        # 1:  'start+':  expected number of serials, starting at start
 | 
			
		||||
 
 | 
			
		||||
@@ -257,6 +257,16 @@ class TestSerialNumberExtraction(TestCase):
 | 
			
		||||
        self.assertEqual(len(sn), 5)
 | 
			
		||||
        self.assertEqual(sn, [1, 2, 4, 5, 6])
 | 
			
		||||
 | 
			
		||||
        # 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)
 | 
			
		||||
        self.assertEqual(sn, [1, 2, "TG-4SR-92", 4, 5])
 | 
			
		||||
 | 
			
		||||
        # Test groups are not interpolated with alpha characters
 | 
			
		||||
        sn = e("1, A-2, 3+", 5, 1)
 | 
			
		||||
        self.assertEqual(len(sn), 5)
 | 
			
		||||
        self.assertEqual(sn, [1, "A-2", 3, 4, 5])
 | 
			
		||||
 | 
			
		||||
        # Test multiple placeholders
 | 
			
		||||
        sn = e("1 2 ~ ~ ~", 5, 3)
 | 
			
		||||
        self.assertEqual(len(sn), 5)
 | 
			
		||||
@@ -317,6 +327,10 @@ class TestSerialNumberExtraction(TestCase):
 | 
			
		||||
        with self.assertRaises(ValidationError):
 | 
			
		||||
            e("10, a, 7-70j", 4, 1)
 | 
			
		||||
 | 
			
		||||
        # Test groups are not interpolated with word characters
 | 
			
		||||
        with self.assertRaises(ValidationError):
 | 
			
		||||
            e("1, 2, 3, E-5", 5, 1)
 | 
			
		||||
 | 
			
		||||
    def test_combinations(self):
 | 
			
		||||
        e = helpers.extract_serial_numbers
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user