mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
generalising for done()
This commit is contained in:
parent
ad4902ea44
commit
64f8846e99
@ -450,6 +450,33 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_clean_items(self):
|
||||||
|
""" returns dict with all cleaned values """
|
||||||
|
items = {}
|
||||||
|
|
||||||
|
for form_key, form_value in self.get_all_cleaned_data().items():
|
||||||
|
# Split key from row value
|
||||||
|
try:
|
||||||
|
(field, idx) = form_key.split('-')
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
if idx not in items:
|
||||||
|
# Insert into items
|
||||||
|
items.update({
|
||||||
|
idx: {
|
||||||
|
self.form_field_map[field]: form_value,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
# Update items
|
||||||
|
items[idx][self.form_field_map[field]] = form_value
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return items
|
||||||
|
|
||||||
def check_field_selection(self, form):
|
def check_field_selection(self, form):
|
||||||
""" Check field matching """
|
""" Check field matching """
|
||||||
|
|
||||||
|
@ -767,26 +767,7 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
""" Once all the data is in, process it to add PurchaseOrderLineItem instances to the order """
|
""" Once all the data is in, process it to add PurchaseOrderLineItem instances to the order """
|
||||||
|
|
||||||
order = self.get_order()
|
order = self.get_order()
|
||||||
|
items = self.get_clean_items()
|
||||||
items = {}
|
|
||||||
|
|
||||||
for form_key, form_value in self.get_all_cleaned_data().items():
|
|
||||||
# Split key from row value
|
|
||||||
try:
|
|
||||||
(field, idx) = form_key.split('-')
|
|
||||||
except ValueError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if idx not in items:
|
|
||||||
# Insert into items
|
|
||||||
items.update({
|
|
||||||
idx: {
|
|
||||||
self.form_field_map[field]: form_value,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
# Update items
|
|
||||||
items[idx][self.form_field_map[field]] = form_value
|
|
||||||
|
|
||||||
# Create PurchaseOrderLineItem instances
|
# Create PurchaseOrderLineItem instances
|
||||||
for purchase_order_item in items.values():
|
for purchase_order_item in items.values():
|
||||||
|
@ -822,28 +822,7 @@ class PartImport(FileManagementFormView):
|
|||||||
|
|
||||||
def done(self, form_list, **kwargs):
|
def done(self, form_list, **kwargs):
|
||||||
""" Create items """
|
""" Create items """
|
||||||
items = {}
|
items = self.get_clean_items()
|
||||||
|
|
||||||
for form_key, form_value in self.get_all_cleaned_data().items():
|
|
||||||
# Split key from row value
|
|
||||||
try:
|
|
||||||
(field, idx) = form_key.split('-')
|
|
||||||
except ValueError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
if idx not in items:
|
|
||||||
# Insert into items
|
|
||||||
items.update({
|
|
||||||
idx: {
|
|
||||||
self.form_field_map[field]: form_value,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
# Update items
|
|
||||||
items[idx][self.form_field_map[field]] = form_value
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
import_done = 0
|
import_done = 0
|
||||||
import_error = []
|
import_error = []
|
||||||
|
Loading…
Reference in New Issue
Block a user