diff --git a/frappe/email/doctype/contact/contact.py b/frappe/email/doctype/contact/contact.py index 796f9ddb99..2eca1b7760 100644 --- a/frappe/email/doctype/contact/contact.py +++ b/frappe/email/doctype/contact/contact.py @@ -125,19 +125,19 @@ def contact_query(doctype, txt, searchfield, start, page_len, filters): ) return frappe.db.sql("""select - contact.name, contact.first_name, contact.last_name + `tabContact`.name, `tabContact`.first_name, `tabContact`.last_name from - tabContact as contact, `tabDynamic Link` as dl + `tabContact`, `tabDynamic Link` where - dl.parent = contact.name and - dl.parenttype = 'Contact' and - dl.link_doctype = %(link_doctype)s and - dl.link_name = %(link_name)s and - contact.`{key}` like %(txt)s + `tabDynamic Link`.parent = `tabContact`.name and + `tabDynamic Link`.parenttype = 'Contact' and + `tabDynamic Link`.link_doctype = %(link_doctype)s and + `tabDynamic Link`.link_name = %(link_name)s and + `tabContact`.`{key}` like %(txt)s {mcond} order by - if(locate(%(_txt)s, contact.name), locate(%(_txt)s, contact.name), 99999), - contact.idx desc, contact.name + if(locate(%(_txt)s, `tabContact`.name), locate(%(_txt)s, `tabContact`.name), 99999), + `tabContact`.idx desc, `tabContact`.name limit %(start)s, %(page_len)s """.format( mcond=get_match_cond(doctype), key=frappe.db.escape(searchfield)), diff --git a/frappe/geo/doctype/address/address.py b/frappe/geo/doctype/address/address.py index bf5859a757..f185cb50e8 100644 --- a/frappe/geo/doctype/address/address.py +++ b/frappe/geo/doctype/address/address.py @@ -198,19 +198,19 @@ def address_query(doctype, txt, searchfield, start, page_len, filters): ) return frappe.db.sql("""select - address.name, address.city, address.country + `tabAddress`.name, `tabAddress`.city, `tabAddress`.country from - tabAddress as address, `tabDynamic Link` as dl + `tabAddress`, `tabDynamic Link` where - dl.parent = address.name and - dl.parenttype = 'Address' and - dl.link_doctype = %(link_doctype)s and - dl.link_name = %(link_name)s and - address.`{key}` like %(txt)s + `tabDynamic Link`.parent = `tabAddress`.name and + `tabDynamic Link`.parenttype = 'Address' and + `tabDynamic Link`.link_doctype = %(link_doctype)s and + `tabDynamic Link`.link_name = %(link_name)s and + `tabAddress`.`{key}` like %(txt)s {mcond} {condition} order by - if(locate(%(_txt)s, address.name), locate(%(_txt)s, address.name), 99999), - address.idx desc, address.name + if(locate(%(_txt)s, `tabAddress`.name), locate(%(_txt)s, `tabAddress`.name), 99999), + `tabAddress`.idx desc, `tabAddress`.name limit %(start)s, %(page_len)s """.format( mcond=get_match_cond(doctype), key=frappe.db.escape(searchfield),