Merge pull request #1407 from eeintech/bom_match_headers

Split required and part match headers for BOM import
This commit is contained in:
Oliver 2021-03-16 08:19:32 +11:00 committed by GitHub
commit 5e48009241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -232,14 +232,18 @@ class BomUploadManager:
# Fields which are absolutely necessary for valid upload # Fields which are absolutely necessary for valid upload
REQUIRED_HEADERS = [ REQUIRED_HEADERS = [
'Part_Name',
'Quantity' '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 # Fields which would be helpful but are not required
OPTIONAL_HEADERS = [ OPTIONAL_HEADERS = [
'Part_IPN',
'Part_ID',
'Reference', 'Reference',
'Note', 'Note',
'Overage', 'Overage',
@ -251,7 +255,7 @@ class BomUploadManager:
'Overage' 'Overage'
] ]
HEADERS = REQUIRED_HEADERS + OPTIONAL_HEADERS HEADERS = REQUIRED_HEADERS + PART_MATCH_HEADERS + OPTIONAL_HEADERS
def __init__(self, bom_file): def __init__(self, bom_file):
""" Initialize the BomUpload class with a user-uploaded file object """ """ Initialize the BomUpload class with a user-uploaded file object """

View File

@ -1372,7 +1372,7 @@ class Part(MPTTModel):
""" Check if the BOM is 'valid' - if the calculated checksum matches the stored value """ Check if the BOM is 'valid' - if the calculated checksum matches the stored value
""" """
return self.get_bom_hash() == self.bom_checksum return self.get_bom_hash() == self.bom_checksum or not self.has_bom
@transaction.atomic @transaction.atomic
def validate_bom(self, user): def validate_bom(self, user):

View File

@ -1425,10 +1425,23 @@ class BomUpload(InvenTreeRoleMixin, FormView):
# Are there any missing columns? # Are there any missing columns?
self.missing_columns = [] self.missing_columns = []
# Check that all required fields are present
for col in BomUploadManager.REQUIRED_HEADERS: for col in BomUploadManager.REQUIRED_HEADERS:
if col not in self.column_selections.values(): if col not in self.column_selections.values():
self.missing_columns.append(col) 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): def handleFieldSelection(self):
""" Handle the output of the field selection form. """ Handle the output of the field selection form.
Here the user is presented with the raw data and must select the Here the user is presented with the raw data and must select the