mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
refactor and doc
This commit is contained in:
parent
e49256a218
commit
616dd76f8a
@ -576,6 +576,7 @@ class SalesOrderShip(AjaxUpdateView):
|
|||||||
class PurchaseOrderUpload(FileManagementFormView):
|
class PurchaseOrderUpload(FileManagementFormView):
|
||||||
''' PurchaseOrder: Upload file, match to fields and parts (using multi-Step form) '''
|
''' PurchaseOrder: Upload file, match to fields and parts (using multi-Step form) '''
|
||||||
|
|
||||||
|
# overriden classes
|
||||||
class MyMatch(cm_forms.MatchItem):
|
class MyMatch(cm_forms.MatchItem):
|
||||||
""" override MatchItem fields """
|
""" override MatchItem fields """
|
||||||
def get_special_field(self, col_guess, row, file_manager):
|
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', '')),
|
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'
|
name = 'order'
|
||||||
form_list_override = [
|
form_list_override = [
|
||||||
@ -630,26 +648,7 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
'reference': 'reference',
|
'reference': 'reference',
|
||||||
'notes': 'notes',
|
'notes': 'notes',
|
||||||
}
|
}
|
||||||
class MyManger(FileManager):
|
file_manager_class = MyFileManager
|
||||||
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
|
|
||||||
|
|
||||||
def get_order(self):
|
def get_order(self):
|
||||||
""" Get order or return 404 """
|
""" Get order or return 404 """
|
||||||
|
@ -796,16 +796,18 @@ class PartImport(FileManagementFormView):
|
|||||||
|
|
||||||
# setup
|
# setup
|
||||||
self.file_manager.setup()
|
self.file_manager.setup()
|
||||||
# collect reference indexes
|
# collect submitted column indexes
|
||||||
idx_s = {}
|
col_ids = {}
|
||||||
for col in self.file_manager.HEADERS:
|
for col in self.file_manager.HEADERS:
|
||||||
index = self.get_column_index(col)
|
index = self.get_column_index(col)
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
idx_s[col] = index
|
col_ids[col] = index
|
||||||
|
|
||||||
|
# parse all rows
|
||||||
for row in self.rows:
|
for row in self.rows:
|
||||||
for idx in idx_s:
|
# check each submitted column
|
||||||
data = row['data'][idx_s[idx]]['cell']
|
for idx in col_ids:
|
||||||
|
data = row['data'][col_ids[idx]]['cell']
|
||||||
|
|
||||||
if idx in self.file_manager.OPTIONAL_MATCH_HEADERS:
|
if idx in self.file_manager.OPTIONAL_MATCH_HEADERS:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user