From d97e3cd4e5d85e0ebf71ad0f653e43358f872d21 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 24 Oct 2021 00:19:17 +0200 Subject: [PATCH] create stock on import --- InvenTree/part/views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 918c015f94..5456f4e049 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -42,7 +42,7 @@ from common.files import FileManager from common.views import FileManagementFormView, FileManagementAjaxView from common.forms import UploadFileForm, MatchFieldForm -from stock.models import StockLocation +from stock.models import StockItem, StockLocation import common.settings as inventree_settings @@ -268,6 +268,7 @@ class PartImport(FileManagementFormView): 'Salable', 'Trackable', 'Virtual', + 'Stock', ] name = 'part' @@ -307,6 +308,7 @@ class PartImport(FileManagementFormView): 'salable': 'salable', 'trackable': 'trackable', 'virtual': 'virtual', + 'stock': 'stock', } file_manager_class = PartFileManager @@ -403,6 +405,15 @@ class PartImport(FileManagementFormView): ) try: new_part.save() + + # add stock item if set + if part_data.get('stock', None): + stock = StockItem( + part=new_part, + location=new_part.default_location, + quantity=int(part_data.get('stock', 1)), + ) + stock.save() import_done += 1 except ValidationError as _e: import_error.append(', '.join(set(_e.messages)))