From 2949289fabe9a4ed6468ff86e71daf6ee98c26e9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 6 Feb 2020 23:11:47 +1100 Subject: [PATCH] Fix for bug a) - Would not create new StockItem for trackable part if Serial Numbers not provided --- InvenTree/stock/forms.py | 1 - InvenTree/stock/views.py | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 5c84f3b4df..ca206ca49d 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -44,7 +44,6 @@ class CreateStockItemForm(HelperForm): 'serial_numbers', 'delete_on_deplete', 'status', - 'notes', 'URL', ] diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index cb478e42f3..9b5c65f37a 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -911,7 +911,19 @@ class StockItemCreate(AjaxCreateView): form.errors['serial_numbers'] = e.messages valid = False - else: + else: + # We have a serialized part, but no serial numbers specified... + form.clean() + form._post_clean() + + item = form.save(commit=False) + item.save(user=request.user) + + data['pk'] = item.pk + data['url'] = item.get_absolute_url() + data['success'] = _("Created new stock item") + + else: # Referenced Part object is not marked as "trackable" # For non-serialized items, simply save the form. # We need to call _post_clean() here because it is prevented in the form implementation form.clean()