brotherton-erpnext/erpnext/projects/utils.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1022 B
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
2013-02-28 13:12:46 +00:00
# For license information, please see license.txt
2014-02-14 10:17:51 +00:00
import frappe
2013-02-28 13:12:46 +00:00
2014-02-14 10:17:51 +00:00
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def query_task(doctype, txt, searchfield, start, page_len, filters):
2014-09-09 10:45:35 +00:00
from frappe.desk.reportview import build_match_conditions
2015-11-17 12:57:50 +00:00
search_string = "%%%s%%" % txt
order_by_string = "%s%%" % txt
match_conditions = build_match_conditions("Task")
match_conditions = ("and" + match_conditions) if match_conditions else ""
2015-11-17 12:57:50 +00:00
2014-02-26 07:05:33 +00:00
return frappe.db.sql(
"""select name, subject from `tabTask`
where (`%s` like %s or `subject` like %s) %s
order by
case when `subject` like %s then 0 else 1 end,
case when `%s` like %s then 0 else 1 end,
`%s`,
subject
2015-11-17 12:57:50 +00:00
limit %s, %s"""
% (searchfield, "%s", "%s", match_conditions, "%s", searchfield, "%s", searchfield, "%s", "%s"),
2015-11-17 12:57:50 +00:00
(search_string, search_string, order_by_string, order_by_string, start, page_len),
)