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 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 20 | return frappe.db.sql( |
| 21 | """select name, subject from `tabTask` |
Akhil Narang | 3effaf2 | 2024-03-27 11:37:26 +0530 | [diff] [blame] | 22 | where (`{}` like {} or `subject` like {}) {} |
Anand Doshi | 9e1d120 | 2013-05-09 19:34:34 +0530 | [diff] [blame] | 23 | order by |
Akhil Narang | 3effaf2 | 2024-03-27 11:37:26 +0530 | [diff] [blame] | 24 | case when `subject` like {} then 0 else 1 end, |
| 25 | case when `{}` like {} then 0 else 1 end, |
| 26 | `{}`, |
Anand Doshi | 9e1d120 | 2013-05-09 19:34:34 +0530 | [diff] [blame] | 27 | subject |
Akhil Narang | 3effaf2 | 2024-03-27 11:37:26 +0530 | [diff] [blame] | 28 | limit {} offset {}""".format( |
| 29 | searchfield, "%s", "%s", match_conditions, "%s", searchfield, "%s", searchfield, "%s", "%s" |
| 30 | ), |
Conor | 00ef499 | 2022-06-14 00:19:07 -0500 | [diff] [blame] | 31 | (search_string, search_string, order_by_string, order_by_string, page_len, start), |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 32 | ) |