diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 3db0d4412f..9aa9b8d473 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -576,6 +576,7 @@ class SalesOrderShip(AjaxUpdateView): class PurchaseOrderUpload(FileManagementFormView): ''' PurchaseOrder: Upload file, match to fields and parts (using multi-Step form) ''' + # overriden classes class MyMatch(cm_forms.MatchItem): """ override MatchItem fields """ def get_special_field(self, col_guess, row, file_manager): @@ -607,7 +608,24 @@ class PurchaseOrderUpload(FileManagementFormView): default_amount=self.clean_nbr(row.get('price', '')), ) + class MyFileManager(FileManager): + def setup(self): + self.REQUIRED_HEADERS = [ + 'Quantity', + ] + self.ITEM_MATCH_HEADERS = [ + 'Manufacturer_MPN', + 'Supplier_SKU', + ] + + self.OPTIONAL_HEADERS = [ + 'Purchase_Price', + 'Reference', + 'Notes', + ] + + return super().setup() name = 'order' form_list_override = [ @@ -630,26 +648,7 @@ class PurchaseOrderUpload(FileManagementFormView): 'reference': 'reference', 'notes': 'notes', } - class MyManger(FileManager): - def setup(self): - self.REQUIRED_HEADERS = [ - 'Quantity', - ] - - self.ITEM_MATCH_HEADERS = [ - 'Manufacturer_MPN', - 'Supplier_SKU', - ] - - self.OPTIONAL_HEADERS = [ - 'Purchase_Price', - 'Reference', - 'Notes', - ] - - return super().setup() - - file_manager_class = MyManger + file_manager_class = MyFileManager def get_order(self): """ Get order or return 404 """ diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 45a5ad1c2b..65a5cc652d 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -796,16 +796,18 @@ class PartImport(FileManagementFormView): # setup self.file_manager.setup() - # collect reference indexes - idx_s = {} + # collect submitted column indexes + col_ids = {} for col in self.file_manager.HEADERS: index = self.get_column_index(col) if index >= 0: - idx_s[col] = index + col_ids[col] = index + # parse all rows for row in self.rows: - for idx in idx_s: - data = row['data'][idx_s[idx]]['cell'] + # check each submitted column + for idx in col_ids: + data = row['data'][col_ids[idx]]['cell'] if idx in self.file_manager.OPTIONAL_MATCH_HEADERS: try: