blob: d0d88ebdf067bad0261416a58196b1adb62b1e9c [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
6from __future__ import unicode_literals
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05307import frappe
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +05308
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05309@frappe.whitelist()
Anand Doshi9e1d1202013-05-09 19:34:34 +053010def query_task(doctype, txt, searchfield, start, page_len, filters):
Rushabh Mehtac0bb4532014-09-09 16:15:35 +053011 from frappe.desk.reportview import build_match_conditions
Anand Doshida797402015-11-17 18:27:50 +053012
Anand Doshi9e1d1202013-05-09 19:34:34 +053013 search_string = "%%%s%%" % txt
14 order_by_string = "%s%%" % txt
Anand Doshi0d504492013-05-13 15:15:20 +053015 match_conditions = build_match_conditions("Task")
16 match_conditions = ("and" + match_conditions) if match_conditions else ""
Anand Doshida797402015-11-17 18:27:50 +053017
Anand Doshie9baaa62014-02-26 12:35:33 +053018 return frappe.db.sql("""select name, subject from `tabTask`
Anand Doshi0d504492013-05-13 15:15:20 +053019 where (`%s` like %s or `subject` like %s) %s
Anand Doshi9e1d1202013-05-09 19:34:34 +053020 order by
21 case when `subject` like %s then 0 else 1 end,
22 case when `%s` like %s then 0 else 1 end,
23 `%s`,
24 subject
Anand Doshida797402015-11-17 18:27:50 +053025 limit %s, %s""" %
Suraj Shettybfc195d2018-09-21 10:20:52 +053026 (searchfield, "%s", "%s", match_conditions, "%s",
27 searchfield, "%s", searchfield, "%s", "%s"),
Anand Doshida797402015-11-17 18:27:50 +053028 (search_string, search_string, order_by_string, order_by_string, start, page_len))