From 437352db7403ddbdfc11f67fb16dcd9bfea37b29 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 21 Aug 2019 16:35:42 +0530 Subject: [PATCH] fix: added searchfield to address querry --- frappe/contacts/doctype/address/address.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frappe/contacts/doctype/address/address.py b/frappe/contacts/doctype/address/address.py index 57ed4e937f..80b1c1fbe4 100644 --- a/frappe/contacts/doctype/address/address.py +++ b/frappe/contacts/doctype/address/address.py @@ -237,6 +237,19 @@ def address_query(doctype, txt, searchfield, start, page_len, filters): value=value ) + meta = frappe.get_meta("Address") + searchfields = meta.get_search_fields() + + if searchfield: + searchfields.append(searchfield) + + search_condition = '' + for field in searchfields: + if search_condition == '': + search_condition += '`tabAddress`.`{field}` like %(txt)s'.format(field=field) + else: + search_condition += ' or `tabAddress`.`{field}` like %(txt)s'.format(field=field) + return frappe.db.sql("""select `tabAddress`.name, `tabAddress`.city, `tabAddress`.country from @@ -247,7 +260,7 @@ def address_query(doctype, txt, searchfield, start, page_len, filters): `tabDynamic Link`.link_doctype = %(link_doctype)s and `tabDynamic Link`.link_name = %(link_name)s and ifnull(`tabAddress`.disabled, 0) = 0 and - `tabAddress`.`{key}` like %(txt)s + ({search_condition}) {mcond} {condition} order by if(locate(%(_txt)s, `tabAddress`.name), locate(%(_txt)s, `tabAddress`.name), 99999), @@ -255,6 +268,7 @@ def address_query(doctype, txt, searchfield, start, page_len, filters): limit %(start)s, %(page_len)s """.format( mcond=get_match_cond(doctype), key=searchfield, + search_condition = search_condition, condition=condition or ""), { 'txt': '%' + txt + '%', '_txt': txt.replace("%", ""),