blob: 5d7455039af539fdd93135e019da310f46371e7f [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
3
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +05304# For license information, please see license.txt
5
Chillar Anand915b3432021-09-02 16:44:59 +05306
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05307import frappe
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +05308
Chillar Anand915b3432021-09-02 16:44:59 +05309
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053010@frappe.whitelist()
Suraj Shetty1923ef02020-08-05 19:42:25 +053011@frappe.validate_and_sanitize_search_inputs
Anand Doshi9e1d1202013-05-09 19:34:34 +053012def query_task(doctype, txt, searchfield, start, page_len, filters):
Rushabh Mehtac0bb4532014-09-09 16:15:35 +053013 from frappe.desk.reportview import build_match_conditions
Anand Doshida797402015-11-17 18:27:50 +053014
Anand Doshi9e1d1202013-05-09 19:34:34 +053015 search_string = "%%%s%%" % txt
16 order_by_string = "%s%%" % txt
Anand Doshi0d504492013-05-13 15:15:20 +053017 match_conditions = build_match_conditions("Task")
18 match_conditions = ("and" + match_conditions) if match_conditions else ""
Anand Doshida797402015-11-17 18:27:50 +053019
Anand Doshie9baaa62014-02-26 12:35:33 +053020 return frappe.db.sql("""select name, subject from `tabTask`
Anand Doshi0d504492013-05-13 15:15:20 +053021 where (`%s` like %s or `subject` like %s) %s
Anand Doshi9e1d1202013-05-09 19:34:34 +053022 order by
23 case when `subject` like %s then 0 else 1 end,
24 case when `%s` like %s then 0 else 1 end,
25 `%s`,
26 subject
Anand Doshida797402015-11-17 18:27:50 +053027 limit %s, %s""" %
Suraj Shettybfc195d2018-09-21 10:20:52 +053028 (searchfield, "%s", "%s", match_conditions, "%s",
29 searchfield, "%s", searchfield, "%s", "%s"),
Anand Doshida797402015-11-17 18:27:50 +053030 (search_string, search_string, order_by_string, order_by_string, start, page_len))