test commit

This commit is contained in:
Ali 2025-05-22 18:30:55 +04:00
parent a761c46202
commit ea76b90848
1 changed files with 12 additions and 12 deletions

View File

@ -1905,7 +1905,7 @@ def match_similar_parties():
'etaxes_party_type', 'erp_party_type']) 'etaxes_party_type', 'erp_party_type'])
# Log parties # Log parties
frappe.log_error(f"E-Taxes parties with status New: {etaxes_parties}", "Match Parties Log") # frappe.log_error(f"E-Taxes parties with status New: {etaxes_parties}", "Match Parties Log")
# Get existing mappings # Get existing mappings
existing_mappings = {} existing_mappings = {}
@ -1913,7 +1913,7 @@ def match_similar_parties():
existing_mappings[mapping.etaxes_party_name] = mapping.erp_party existing_mappings[mapping.etaxes_party_name] = mapping.erp_party
# Log existing mappings # Log existing mappings
frappe.log_error(f"Existing mappings: {existing_mappings}", "Match Parties Log") # frappe.log_error(f"Existing mappings: {existing_mappings}", "Match Parties Log")
# Filter only those that are not in mappings or have empty mappings # Filter only those that are not in mappings or have empty mappings
parties_to_process = [] parties_to_process = []
@ -1922,7 +1922,7 @@ def match_similar_parties():
parties_to_process.append(party) parties_to_process.append(party)
# Log final list of parties to process # Log final list of parties to process
frappe.log_error(f"Parties to process: {parties_to_process}", "Match Parties Log") # frappe.log_error(f"Parties to process: {parties_to_process}", "Match Parties Log")
matched_count = 0 matched_count = 0
total_processed = len(parties_to_process) total_processed = len(parties_to_process)
@ -1936,7 +1936,7 @@ def match_similar_parties():
erp_party_type = etaxes_party.erp_party_type erp_party_type = etaxes_party.erp_party_type
# Log party being processed # Log party being processed
frappe.log_error(f"Processing party: {etaxes_party.etaxes_party_name} (Type: {erp_party_type})", "Match Parties Log") # frappe.log_error(f"Processing party: {etaxes_party.etaxes_party_name} (Type: {erp_party_type})", "Match Parties Log")
# Get all parties of corresponding type from system # Get all parties of corresponding type from system
system_parties = frappe.get_all(erp_party_type, system_parties = frappe.get_all(erp_party_type,
@ -1960,9 +1960,9 @@ def match_similar_parties():
# Calculate similarity coefficient # Calculate similarity coefficient
name_score = SequenceMatcher(None, etaxes_name, party_name_normalized).ratio() name_score = SequenceMatcher(None, etaxes_name, party_name_normalized).ratio()
# Log high matches (more than 0.8) # # Log high matches (more than 0.8)
if name_score > 0.8: # if name_score > 0.8:
frappe.log_error(f"High score: '{etaxes_party.etaxes_party_name}' vs '{party_name}' = {name_score}", "Match Parties Log") # frappe.log_error(f"High score: '{etaxes_party.etaxes_party_name}' vs '{party_name}' = {name_score}", "Match Parties Log")
# Check if this is a better match # Check if this is a better match
if name_score > best_score and name_score >= similarity_threshold: if name_score > best_score and name_score >= similarity_threshold:
@ -1971,7 +1971,7 @@ def match_similar_parties():
if best_match: if best_match:
# Log found match # Log found match
frappe.log_error(f"Match found: '{etaxes_party.etaxes_party_name}' matches with '{best_match.name}' (score: {best_score})", "Match Parties Log") # frappe.log_error(f"Match found: '{etaxes_party.etaxes_party_name}' matches with '{best_match.name}' (score: {best_score})", "Match Parties Log")
# IMPORTANT: check if there is already a record for this party in mappings # IMPORTANT: check if there is already a record for this party in mappings
existing_row = None existing_row = None
@ -2004,17 +2004,17 @@ def match_similar_parties():
party_doc.mapped_party = best_match.name party_doc.mapped_party = best_match.name
party_doc.save() party_doc.save()
except Exception as e: except Exception as e:
frappe.log_error(f"Error updating party status: {str(e)}", "Match Parties Log") return
else: else:
# For parties that have no match, DO NOT change status # For parties that have no match, DO NOT change status
frappe.log_error(f"No match found for '{etaxes_party.etaxes_party_name}', keeping status as 'New'", "Match Parties Log") return
# Save settings after adding all mappings # Save settings after adding all mappings
if matched_count > 0: if matched_count > 0:
doc.save() doc.save()
# Log final result # Log final result
frappe.log_error(f"Final result: matched {matched_count} out of {total_processed} parties", "Match Parties Log") # frappe.log_error(f"Final result: matched {matched_count} out of {total_processed} parties", "Match Parties Log")
return { return {
'success': True, 'success': True,
@ -2024,7 +2024,7 @@ def match_similar_parties():
} }
except Exception as e: except Exception as e:
frappe.log_error(frappe.get_traceback(), f"Error in match_similar_parties: {str(e)}") # frappe.log_error(frappe.get_traceback(), f"Error in match_similar_parties: {str(e)}")
return { return {
'success': False, 'success': False,
'message': "An unknown error occurred, please try again in a few minutes." 'message': "An unknown error occurred, please try again in a few minutes."