diff --git a/InvenTree/common/views.py b/InvenTree/common/views.py index b645d16651..53909cc0d7 100644 --- a/InvenTree/common/views.py +++ b/InvenTree/common/views.py @@ -450,6 +450,33 @@ class FileManagementFormView(MultiStepFormView): """ 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): """ Check field matching """ diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index d89401e3cb..3db0d4412f 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -767,26 +767,7 @@ class PurchaseOrderUpload(FileManagementFormView): """ Once all the data is in, process it to add PurchaseOrderLineItem instances to the order """ order = self.get_order() - - 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 + items = self.get_clean_items() # Create PurchaseOrderLineItem instances for purchase_order_item in items.values(): diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index d3c32bebca..1e5e2153e8 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -822,28 +822,7 @@ class PartImport(FileManagementFormView): def done(self, form_list, **kwargs): """ Create 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 - - 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 + items = self.get_clean_items() import_done = 0 import_error = []