refactor and doc

This commit is contained in:
Matthias 2021-05-18 11:10:01 +02:00
parent e49256a218
commit 616dd76f8a
2 changed files with 26 additions and 25 deletions

View File

@ -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 """

View File

@ -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: