@@ -125,19 +125,19 @@ def contact_query(doctype, txt, searchfield, start, page_len, filters): | |||||
) | ) | ||||
return frappe.db.sql("""select | return frappe.db.sql("""select | ||||
contact.name, contact.first_name, contact.last_name | |||||
`tabContact`.name, `tabContact`.first_name, `tabContact`.last_name | |||||
from | from | ||||
tabContact as contact, `tabDynamic Link` as dl | |||||
`tabContact`, `tabDynamic Link` | |||||
where | 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} | {mcond} | ||||
order by | 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( | limit %(start)s, %(page_len)s """.format( | ||||
mcond=get_match_cond(doctype), | mcond=get_match_cond(doctype), | ||||
key=frappe.db.escape(searchfield)), | key=frappe.db.escape(searchfield)), | ||||
@@ -198,19 +198,19 @@ def address_query(doctype, txt, searchfield, start, page_len, filters): | |||||
) | ) | ||||
return frappe.db.sql("""select | return frappe.db.sql("""select | ||||
address.name, address.city, address.country | |||||
`tabAddress`.name, `tabAddress`.city, `tabAddress`.country | |||||
from | from | ||||
tabAddress as address, `tabDynamic Link` as dl | |||||
`tabAddress`, `tabDynamic Link` | |||||
where | 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} | {mcond} {condition} | ||||
order by | 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( | limit %(start)s, %(page_len)s """.format( | ||||
mcond=get_match_cond(doctype), | mcond=get_match_cond(doctype), | ||||
key=frappe.db.escape(searchfield), | key=frappe.db.escape(searchfield), | ||||