mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
fix: employee search based on the fields mentioned in the doctype searchfields
This commit is contained in:
@@ -42,14 +42,14 @@ def employee_query(
|
|||||||
ptype="select" if frappe.only_has_select_perm(doctype) else "read",
|
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)
|
mcond = "" if ignore_permissions else get_match_cond(doctype)
|
||||||
|
|
||||||
return frappe.db.sql(
|
return frappe.db.sql(
|
||||||
"""select {fields} from `tabEmployee`
|
"""select {fields} from `tabEmployee`
|
||||||
where status in ('Active', 'Suspended')
|
where status in ('Active', 'Suspended')
|
||||||
and docstatus < 2
|
and docstatus < 2
|
||||||
and ({key} like %(txt)s
|
and ({search_conditions})
|
||||||
or employee_name like %(txt)s)
|
|
||||||
{fcond} {mcond}
|
{fcond} {mcond}
|
||||||
order by
|
order by
|
||||||
(case when locate(%(_txt)s, name) > 0 then locate(%(_txt)s, name) else 99999 end),
|
(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(
|
limit %(page_len)s offset %(start)s""".format(
|
||||||
**{
|
**{
|
||||||
"fields": ", ".join(fields),
|
"fields": ", ".join(fields),
|
||||||
"key": searchfield,
|
|
||||||
"fcond": get_filters_cond(doctype, filters, conditions),
|
"fcond": get_filters_cond(doctype, filters, conditions),
|
||||||
"mcond": mcond,
|
"mcond": mcond,
|
||||||
|
"search_conditions": search_conditions,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
||||||
|
|||||||
Reference in New Issue
Block a user