Skip to content

Commit

Permalink
fix 771
Browse files Browse the repository at this point in the history
  • Loading branch information
ealexch committed Jan 14, 2025
1 parent 9c4ec8a commit 526230e
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,20 @@ def __init__(
)
self.notes_mapper.migration_report = self.migration_report

def sanitize_po_number(self, po_number):
def sanitize_po_number(self, po_number, existing_po_numbers):
sanitized_po = re.sub(r'[^A-Za-z0-9]', '', po_number)

if sanitized_po != po_number:
logging.warning(f"Invalid characters removed from PO number: {po_number}")

Check warning on line 93 in src/folio_migration_tools/mapping_file_transformation/order_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/folio_migration_tools/mapping_file_transformation/order_mapper.py#L93

Added line #L93 was not covered by tests

# Check for potential duplicates
if sanitized_po in existing_po_numbers:
Helper.log_data_issue(

Check warning on line 97 in src/folio_migration_tools/mapping_file_transformation/order_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/folio_migration_tools/mapping_file_transformation/order_mapper.py#L97

Added line #L97 was not covered by tests
"Duplicate PO number detected after sanitization",
f"Original: {po_number}, Sanitized: {sanitized_po}"
)

existing_po_numbers.add(sanitized_po)
return sanitized_po

def get_prop(self, legacy_order, folio_prop_name: str, index_or_id, schema_default_value):
Expand Down Expand Up @@ -370,7 +380,12 @@ def inject_items_schema_by_ref(submodule_path, github_headers, property: dict):
return {}

def perform_additional_mapping(self, index_or_id, composite_order):
composite_order["poNumber"] = self.sanitize_po_number(composite_order.get("poNumber", ""))
existing_po_numbers = set()

# Sanitize the PO number and detect duplicates
composite_order["poNumber"] = self.sanitize_po_number(
composite_order.get("poNumber", ""), existing_po_numbers
)

# Get organization UUID from FOLIO
composite_order["vendor"] = self.get_folio_organization_uuid(
Expand Down

0 comments on commit 526230e

Please sign in to comment.