mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
create stock on import
This commit is contained in:
parent
bec845003d
commit
d97e3cd4e5
@ -42,7 +42,7 @@ from common.files import FileManager
|
|||||||
from common.views import FileManagementFormView, FileManagementAjaxView
|
from common.views import FileManagementFormView, FileManagementAjaxView
|
||||||
from common.forms import UploadFileForm, MatchFieldForm
|
from common.forms import UploadFileForm, MatchFieldForm
|
||||||
|
|
||||||
from stock.models import StockLocation
|
from stock.models import StockItem, StockLocation
|
||||||
|
|
||||||
import common.settings as inventree_settings
|
import common.settings as inventree_settings
|
||||||
|
|
||||||
@ -268,6 +268,7 @@ class PartImport(FileManagementFormView):
|
|||||||
'Salable',
|
'Salable',
|
||||||
'Trackable',
|
'Trackable',
|
||||||
'Virtual',
|
'Virtual',
|
||||||
|
'Stock',
|
||||||
]
|
]
|
||||||
|
|
||||||
name = 'part'
|
name = 'part'
|
||||||
@ -307,6 +308,7 @@ class PartImport(FileManagementFormView):
|
|||||||
'salable': 'salable',
|
'salable': 'salable',
|
||||||
'trackable': 'trackable',
|
'trackable': 'trackable',
|
||||||
'virtual': 'virtual',
|
'virtual': 'virtual',
|
||||||
|
'stock': 'stock',
|
||||||
}
|
}
|
||||||
file_manager_class = PartFileManager
|
file_manager_class = PartFileManager
|
||||||
|
|
||||||
@ -403,6 +405,15 @@ class PartImport(FileManagementFormView):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
new_part.save()
|
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
|
import_done += 1
|
||||||
except ValidationError as _e:
|
except ValidationError as _e:
|
||||||
import_error.append(', '.join(set(_e.messages)))
|
import_error.append(', '.join(set(_e.messages)))
|
||||||
|
Loading…
Reference in New Issue
Block a user