diff --git a/crm/integrations/api.py b/crm/integrations/api.py index d8300678..6c4e35e0 100644 --- a/crm/integrations/api.py +++ b/crm/integrations/api.py @@ -110,12 +110,12 @@ def get_contact_by_phone_number(phone_number): number = parse_phone_number(phone_number) if number.get("is_valid"): - return get_contact(number.get("national_number")) + return get_contact(number.get("national_number"), number.get("country")) else: - return get_contact(phone_number, exact_match=True) + return get_contact(phone_number, number.get("country"), exact_match=True) -def get_contact(phone_number, exact_match=False): +def get_contact(phone_number, country="IN", exact_match=False): if not phone_number: return {"mobile_no": phone_number} @@ -149,11 +149,11 @@ def get_contact(phone_number, exact_match=False): deal = frappe.db.get_value( "CRM Contacts", {"contact": contact.name, "is_primary": 1}, "parent" ) - if are_same_phone_number(contact.mobile_no, phone_number, validate=not exact_match): + if are_same_phone_number(contact.mobile_no, phone_number, country, validate=not exact_match): contact["deal"] = deal return contact # Else, return the first contact - if are_same_phone_number(contacts[0].mobile_no, phone_number, validate=not exact_match): + if are_same_phone_number(contacts[0].mobile_no, phone_number, country, validate=not exact_match): return contacts[0] # Else, Check if the number is associated with a lead @@ -173,7 +173,7 @@ def get_contact(phone_number, exact_match=False): if len(leads): for lead in leads: - if are_same_phone_number(lead.mobile_no, phone_number, validate=not exact_match): + if are_same_phone_number(lead.mobile_no, phone_number, country, validate=not exact_match): lead["lead"] = lead.name lead["full_name"] = lead.lead_name return lead