From a7baad33ba360b988b206bf56c995d449629d451 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 18 Jan 2021 14:38:07 +1100 Subject: [PATCH] Fix form error for creating a new stock item --- InvenTree/stock/views.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 163d1ed112..c1078c8355 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -1582,17 +1582,22 @@ class StockItemCreate(AjaxCreateView): sn = str(sn).strip() if len(sn) > 0: - serials = extract_serial_numbers(sn, quantity) + try: + serials = extract_serial_numbers(sn, quantity) + except ValidationError as e: + serials = None + form.add_error('serial_numbers', e) - existing = part.find_conflicting_serial_numbers(serials) + if serials is not None: + existing = part.find_conflicting_serial_numbers(serials) - if len(existing) > 0: - exists = ','.join([str(x) for x in existing]) + if len(existing) > 0: + exists = ','.join([str(x) for x in existing]) - form.add_error( - 'serial_numbers', - _('Serial numbers already exist') + ': ' + exists - ) + form.add_error( + 'serial_numbers', + _('Serial numbers already exist') + ': ' + exists + ) def save(self, form, **kwargs): """