fix: allow search leads by doctype search fields
* fix: allow search leads by doctype search fields * fix: allow search leads by doctype search fields, linters fix
This commit is contained in:
parent
2b59a95162
commit
e12e3bb012
@ -53,13 +53,17 @@ def lead_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
doctype = "Lead"
|
doctype = "Lead"
|
||||||
fields = get_fields(doctype, ["name", "lead_name", "company_name"])
|
fields = get_fields(doctype, ["name", "lead_name", "company_name"])
|
||||||
|
|
||||||
|
searchfields = frappe.get_meta(doctype).get_search_fields()
|
||||||
|
searchfields = " or ".join(field + " like %(txt)s" for field in searchfields)
|
||||||
|
|
||||||
return frappe.db.sql(
|
return frappe.db.sql(
|
||||||
"""select {fields} from `tabLead`
|
"""select {fields} from `tabLead`
|
||||||
where docstatus < 2
|
where docstatus < 2
|
||||||
and ifnull(status, '') != 'Converted'
|
and ifnull(status, '') != 'Converted'
|
||||||
and ({key} like %(txt)s
|
and ({key} like %(txt)s
|
||||||
or lead_name like %(txt)s
|
or lead_name like %(txt)s
|
||||||
or company_name like %(txt)s)
|
or company_name like %(txt)s
|
||||||
|
or {scond})
|
||||||
{mcond}
|
{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),
|
||||||
@ -68,7 +72,12 @@ def lead_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
idx desc,
|
idx desc,
|
||||||
name, lead_name
|
name, lead_name
|
||||||
limit %(page_len)s offset %(start)s""".format(
|
limit %(page_len)s offset %(start)s""".format(
|
||||||
**{"fields": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)}
|
**{
|
||||||
|
"fields": ", ".join(fields),
|
||||||
|
"key": searchfield,
|
||||||
|
"scond": searchfields,
|
||||||
|
"mcond": get_match_cond(doctype),
|
||||||
|
}
|
||||||
),
|
),
|
||||||
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user