Split required and part match headers for BOM import

This commit is contained in:
eeintech 2021-03-15 09:41:04 -04:00
parent ed028aed62
commit d39bd88440
2 changed files with 21 additions and 4 deletions

View File

@ -232,14 +232,18 @@ class BomUploadManager:
# Fields which are absolutely necessary for valid upload
REQUIRED_HEADERS = [
'Part_Name',
'Quantity'
]
# Fields which are used for part matching (only one of them is needed)
PART_MATCH_HEADERS = [
'Part_Name',
'Part_IPN',
'Part_ID',
]
# Fields which would be helpful but are not required
OPTIONAL_HEADERS = [
'Part_IPN',
'Part_ID',
'Reference',
'Note',
'Overage',
@ -251,7 +255,7 @@ class BomUploadManager:
'Overage'
]
HEADERS = REQUIRED_HEADERS + OPTIONAL_HEADERS
HEADERS = REQUIRED_HEADERS + PART_MATCH_HEADERS + OPTIONAL_HEADERS
def __init__(self, bom_file):
""" Initialize the BomUpload class with a user-uploaded file object """

View File

@ -1425,10 +1425,23 @@ class BomUpload(InvenTreeRoleMixin, FormView):
# Are there any missing columns?
self.missing_columns = []
# Check that all required fields are present
for col in BomUploadManager.REQUIRED_HEADERS:
if col not in self.column_selections.values():
self.missing_columns.append(col)
# Check that at least one of the part match field is present
part_match_found = False
for col in BomUploadManager.PART_MATCH_HEADERS:
if col in self.column_selections.values():
part_match_found = True
break
# If not, notify user
if not part_match_found:
for col in BomUploadManager.PART_MATCH_HEADERS:
self.missing_columns.append(col)
def handleFieldSelection(self):
""" Handle the output of the field selection form.
Here the user is presented with the raw data and must select the