Merge pull request #9452 from faztp12/develop

Customer Query include Search fields
This commit is contained in:
Makarand Bauskar 2017-07-03 15:20:23 +05:30 committed by GitHub
commit 1bad1fcc00

View File

@ -68,14 +68,17 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters):
fields = ["name", "customer_name", "customer_group", "territory"] fields = ["name", "customer_name", "customer_group", "territory"]
meta = frappe.get_meta("Customer") meta = frappe.get_meta("Customer")
fields = fields + [f for f in meta.get_search_fields() if not f in fields] searchfields = meta.get_search_fields()
searchfields = searchfields + [f for f in [searchfield or "name", "customer_name"] \
if not f in searchfields]
fields = fields + [f for f in searchfields if not f in fields]
fields = ", ".join(fields) fields = ", ".join(fields)
searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
return frappe.db.sql("""select {fields} from `tabCustomer` return frappe.db.sql("""select {fields} from `tabCustomer`
where docstatus < 2 where docstatus < 2
and ({key} like %(txt)s and ({scond}) and disabled=0
or customer_name like %(txt)s) and disabled=0
{mcond} {mcond}
order by order by
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
@ -84,7 +87,7 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters):
name, customer_name name, customer_name
limit %(start)s, %(page_len)s""".format(**{ limit %(start)s, %(page_len)s""".format(**{
"fields": fields, "fields": fields,
"key": searchfield, "scond": searchfields,
"mcond": get_match_cond(doctype) "mcond": get_match_cond(doctype)
}), { }), {
'txt': "%%%s%%" % txt, 'txt': "%%%s%%" % txt,