refactor: updated find_record logic
This commit is contained in:
parent
a5ff68c717
commit
481d097563
@ -157,24 +157,26 @@ def get_lead_or_deal_from_number(call):
|
|||||||
"""Get lead/deal from the given number.
|
"""Get lead/deal from the given number.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def find_record(doctype, mobile_no):
|
def find_record(doctype, mobile_no, where=''):
|
||||||
mobile_no = parse_mobile_no(mobile_no)
|
mobile_no = parse_mobile_no(mobile_no)
|
||||||
data = frappe.db.sql(
|
|
||||||
"""
|
query = f"""
|
||||||
SELECT name, mobile_no
|
SELECT name, mobile_no
|
||||||
FROM `tab{doctype}`
|
FROM `tab{doctype}`
|
||||||
WHERE CONCAT('+', REGEXP_REPLACE(mobile_no, '[^0-9]', '')) = {mobile_no}
|
WHERE CONCAT('+', REGEXP_REPLACE(mobile_no, '[^0-9]', '')) = {mobile_no}
|
||||||
""".format(doctype=doctype, mobile_no=mobile_no),
|
"""
|
||||||
as_dict=True
|
|
||||||
)
|
data = frappe.db.sql(query + where, as_dict=True)
|
||||||
return data[0].name if data else None
|
return data[0].name if data else None
|
||||||
|
|
||||||
doctype = "CRM Lead"
|
doctype = "CRM Deal"
|
||||||
number = call.get('to') if call.type == 'Outgoing' else call.get('from')
|
number = call.get('to') if call.type == 'Outgoing' else call.get('from')
|
||||||
|
|
||||||
doc = find_record(doctype, number) or None
|
doc = find_record(doctype, number) or None
|
||||||
if not doc:
|
if not doc:
|
||||||
doctype = "CRM Deal"
|
doctype = "CRM Lead"
|
||||||
doc = find_record(doctype, number)
|
doc = find_record(doctype, number, 'AND converted is not True')
|
||||||
|
if not doc:
|
||||||
|
doc = find_record(doctype, number)
|
||||||
|
|
||||||
return doc, doctype
|
return doc, doctype
|
||||||
Loading…
x
Reference in New Issue
Block a user