From d39bd88440ebeb260b521c057a90ad18c87d514f Mon Sep 17 00:00:00 2001 From: eeintech Date: Mon, 15 Mar 2021 09:41:04 -0400 Subject: [PATCH 1/2] Split required and part match headers for BOM import --- InvenTree/part/bom.py | 12 ++++++++---- InvenTree/part/views.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/InvenTree/part/bom.py b/InvenTree/part/bom.py index 092b3e3183..ccde26e2f7 100644 --- a/InvenTree/part/bom.py +++ b/InvenTree/part/bom.py @@ -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 """ diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 65f859566b..b4400bcb6d 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -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 From 64a57128bc78ce137ad47e6ebeaf623a80d81a3c Mon Sep 17 00:00:00 2001 From: eeintech Date: Mon, 15 Mar 2021 10:36:12 -0400 Subject: [PATCH 2/2] Return True for BOM valid flag if part does not have BOM items --- InvenTree/part/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index b06469699b..2824a89e75 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1372,7 +1372,7 @@ class Part(MPTTModel): """ 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 def validate_bom(self, user):