Merge pull request #3989 from anandpdoshi/customer-query-match-condition
Customer match condition in autosuggest
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index fe68966..5cbf243 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -10,6 +10,7 @@
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.utilities.address_and_contact import load_address_and_contact
+from frappe.desk.reportview import build_match_conditions
class Customer(TransactionBase):
def get_feed(self):
@@ -146,11 +147,16 @@
else:
fields = ["name", "customer_name", "customer_group", "territory"]
+ match_conditions = build_match_conditions("Customer")
+ match_conditions = "and {}".format(match_conditions) if match_conditions else ""
+
return frappe.db.sql("""select %s from `tabCustomer` where docstatus < 2
- and (%s like %s or customer_name like %s) order by
+ and (%s like %s or customer_name like %s)
+ {match_conditions}
+ order by
case when name like %s then 0 else 1 end,
case when customer_name like %s then 0 else 1 end,
- name, customer_name limit %s, %s""" %
+ name, customer_name limit %s, %s""".format(match_conditions=match_conditions) %
(", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len))