Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 4 | # For license information, please see license.txt |
| 5 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 6 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 7 | import frappe |
Rushabh Mehta | b21eb9a | 2013-02-28 18:42:46 +0530 | [diff] [blame] | 8 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 9 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 10 | @frappe.whitelist() |
Suraj Shetty | 1923ef0 | 2020-08-05 19:42:25 +0530 | [diff] [blame] | 11 | @frappe.validate_and_sanitize_search_inputs |
Anand Doshi | 9e1d120 | 2013-05-09 19:34:34 +0530 | [diff] [blame] | 12 | def query_task(doctype, txt, searchfield, start, page_len, filters): |
Rushabh Mehta | c0bb453 | 2014-09-09 16:15:35 +0530 | [diff] [blame] | 13 | from frappe.desk.reportview import build_match_conditions |
Anand Doshi | da79740 | 2015-11-17 18:27:50 +0530 | [diff] [blame] | 14 | |
Anand Doshi | 9e1d120 | 2013-05-09 19:34:34 +0530 | [diff] [blame] | 15 | search_string = "%%%s%%" % txt |
| 16 | order_by_string = "%s%%" % txt |
Anand Doshi | 0d50449 | 2013-05-13 15:15:20 +0530 | [diff] [blame] | 17 | match_conditions = build_match_conditions("Task") |
| 18 | match_conditions = ("and" + match_conditions) if match_conditions else "" |
Anand Doshi | da79740 | 2015-11-17 18:27:50 +0530 | [diff] [blame] | 19 | |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 20 | return frappe.db.sql("""select name, subject from `tabTask` |
Anand Doshi | 0d50449 | 2013-05-13 15:15:20 +0530 | [diff] [blame] | 21 | where (`%s` like %s or `subject` like %s) %s |
Anand Doshi | 9e1d120 | 2013-05-09 19:34:34 +0530 | [diff] [blame] | 22 | 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 Doshi | da79740 | 2015-11-17 18:27:50 +0530 | [diff] [blame] | 27 | limit %s, %s""" % |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 28 | (searchfield, "%s", "%s", match_conditions, "%s", |
| 29 | searchfield, "%s", searchfield, "%s", "%s"), |
Anand Doshi | da79740 | 2015-11-17 18:27:50 +0530 | [diff] [blame] | 30 | (search_string, search_string, order_by_string, order_by_string, start, page_len)) |