mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
[#2885] Don't interpolate serial groups if they are not numeric
This commit is contained in:
parent
1dba9f66fb
commit
b08efa4de7
@ -466,7 +466,7 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
|
|||||||
if '-' in group:
|
if '-' in group:
|
||||||
items = group.split('-')
|
items = group.split('-')
|
||||||
|
|
||||||
if len(items) == 2:
|
if len(items) == 2 and all([i.isnumeric() for i in items]):
|
||||||
a = items[0].strip()
|
a = items[0].strip()
|
||||||
b = items[1].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))
|
errors.append(_("Invalid group: {g}").format(g=group))
|
||||||
continue
|
continue
|
||||||
else:
|
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
|
# plus signals either
|
||||||
# 1: 'start+': expected number of serials, starting at start
|
# 1: 'start+': expected number of serials, starting at start
|
||||||
|
@ -257,6 +257,16 @@ class TestSerialNumberExtraction(TestCase):
|
|||||||
self.assertEqual(len(sn), 5)
|
self.assertEqual(len(sn), 5)
|
||||||
self.assertEqual(sn, [1, 2, 4, 5, 6])
|
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
|
# Test multiple placeholders
|
||||||
sn = e("1 2 ~ ~ ~", 5, 3)
|
sn = e("1 2 ~ ~ ~", 5, 3)
|
||||||
self.assertEqual(len(sn), 5)
|
self.assertEqual(len(sn), 5)
|
||||||
@ -317,6 +327,10 @@ class TestSerialNumberExtraction(TestCase):
|
|||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
e("10, a, 7-70j", 4, 1)
|
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):
|
def test_combinations(self):
|
||||||
e = helpers.extract_serial_numbers
|
e = helpers.extract_serial_numbers
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user