From 09541c52e18d183311159fc0c51e9bed98fc586a Mon Sep 17 00:00:00 2001 From: thomasantony12 Date: Sun, 6 Jul 2025 11:22:24 +0530 Subject: [PATCH 1/3] 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}, From 75a00928b5fe599433311b586152afff2ddab044 Mon Sep 17 00:00:00 2001 From: Thomas antony <77287334+thomasantony12@users.noreply.github.com> Date: Sat, 12 Jul 2025 09:48:08 +0530 Subject: [PATCH 2/3] chore: included value in "key" for search condition --- erpnext/controllers/queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index d1e1262d339..90d5a3e649d 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -49,7 +49,7 @@ def employee_query( """select {fields} from `tabEmployee` where status in ('Active', 'Suspended') and docstatus < 2 - and ({search_conditions}) + and ({key} like %(txt)s or {search_conditions}) {fcond} {mcond} order by (case when locate(%(_txt)s, name) > 0 then locate(%(_txt)s, name) else 99999 end), From de56faf862dabc9d7aeced16f59747dc650c6d75 Mon Sep 17 00:00:00 2001 From: Thomas antony <77287334+thomasantony12@users.noreply.github.com> Date: Sat, 12 Jul 2025 10:18:34 +0530 Subject: [PATCH 3/3] chore: add missing key value --- erpnext/controllers/queries.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 90d5a3e649d..eef40f3dc40 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -59,6 +59,7 @@ 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,