From 09541c52e18d183311159fc0c51e9bed98fc586a Mon Sep 17 00:00:00 2001 From: thomasantony12 Date: Sun, 6 Jul 2025 11:22:24 +0530 Subject: [PATCH] fix: employee search based on the fields mentioned in the doctype searchfields --- erpnext/controllers/queries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 7c3276fdac0..d1e1262d339 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -42,14 +42,14 @@ def employee_query( ptype="select" if frappe.only_has_select_perm(doctype) else "read", ) + search_conditions = " or ".join([f"{field} like %(txt)s" for field in fields]) mcond = "" if ignore_permissions else get_match_cond(doctype) return frappe.db.sql( """select {fields} from `tabEmployee` where status in ('Active', 'Suspended') and docstatus < 2 - and ({key} like %(txt)s - or employee_name like %(txt)s) + and ({search_conditions}) {fcond} {mcond} order by (case when locate(%(_txt)s, name) > 0 then locate(%(_txt)s, name) else 99999 end), @@ -59,9 +59,9 @@ def employee_query( limit %(page_len)s offset %(start)s""".format( **{ "fields": ", ".join(fields), - "key": searchfield, "fcond": get_filters_cond(doctype, filters, conditions), "mcond": mcond, + "search_conditions": search_conditions, } ), {"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},