blob: eff5f53e18cf857a37a4d602936f04b18c5a8792 [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
Saurabh02875592013-07-08 18:45:55 +05303
4from __future__ import unicode_literals
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05305import frappe
Rushabh Mehtac0bb4532014-09-09 16:15:35 +05306from frappe.desk.reportview import get_match_cond
Rushabh Mehta2e7ad892014-03-06 12:28:47 +05307from frappe.model.db_query import DatabaseQuery
Nabin Hait2ed71ba2015-03-20 15:06:30 +05308from frappe.utils import nowdate
Saurabh02875592013-07-08 18:45:55 +05309
10def get_filters_cond(doctype, filters, conditions):
11 if filters:
Anand Doshi1fef2fa2015-09-14 18:27:21 +053012 flt = filters
Saurabh02875592013-07-08 18:45:55 +053013 if isinstance(filters, dict):
Saurabhf52dc072013-07-10 13:07:49 +053014 filters = filters.items()
15 flt = []
16 for f in filters:
Anand Doshi17350b82013-08-01 15:45:23 +053017 if isinstance(f[1], basestring) and f[1][0] == '!':
Saurabhf52dc072013-07-10 13:07:49 +053018 flt.append([doctype, f[0], '!=', f[1][1:]])
19 else:
20 flt.append([doctype, f[0], '=', f[1]])
Anand Doshibd67e872014-04-11 16:51:27 +053021
Rushabh Mehta2e7ad892014-03-06 12:28:47 +053022 query = DatabaseQuery(doctype)
23 query.filters = flt
24 query.conditions = conditions
Nabin Hait23649c62014-05-07 19:18:15 +053025 query.build_filter_conditions(flt, conditions)
Anand Doshibd67e872014-04-11 16:51:27 +053026
27 cond = ' and ' + ' and '.join(query.conditions)
Saurabh02875592013-07-08 18:45:55 +053028 else:
29 cond = ''
30 return cond
31
Saurabh02875592013-07-08 18:45:55 +053032 # searches for active employees
33def employee_query(doctype, txt, searchfield, start, page_len, filters):
Anand Doshibd67e872014-04-11 16:51:27 +053034 return frappe.db.sql("""select name, employee_name from `tabEmployee`
35 where status = 'Active'
36 and docstatus < 2
Anand Doshi48d3b542014-07-09 13:15:03 +053037 and ({key} like %(txt)s
38 or employee_name like %(txt)s)
39 {mcond}
Anand Doshibd67e872014-04-11 16:51:27 +053040 order by
Anand Doshi48d3b542014-07-09 13:15:03 +053041 if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
42 if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999),
Rushabh Mehta3574b372016-03-11 14:33:04 +053043 idx desc,
Anand Doshi652bc072014-04-16 15:21:46 +053044 name, employee_name
Anand Doshi48d3b542014-07-09 13:15:03 +053045 limit %(start)s, %(page_len)s""".format(**{
46 'key': searchfield,
47 'mcond': get_match_cond(doctype)
48 }), {
49 'txt': "%%%s%%" % txt,
50 '_txt': txt.replace("%", ""),
51 'start': start,
52 'page_len': page_len
53 })
Saurabh02875592013-07-08 18:45:55 +053054
55 # searches for leads which are not converted
Anand Doshibd67e872014-04-11 16:51:27 +053056def lead_query(doctype, txt, searchfield, start, page_len, filters):
Anand Doshie9baaa62014-02-26 12:35:33 +053057 return frappe.db.sql("""select name, lead_name, company_name from `tabLead`
Anand Doshibd67e872014-04-11 16:51:27 +053058 where docstatus < 2
59 and ifnull(status, '') != 'Converted'
Anand Doshi48d3b542014-07-09 13:15:03 +053060 and ({key} like %(txt)s
61 or lead_name like %(txt)s
62 or company_name like %(txt)s)
63 {mcond}
Anand Doshibd67e872014-04-11 16:51:27 +053064 order by
Anand Doshi48d3b542014-07-09 13:15:03 +053065 if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
66 if(locate(%(_txt)s, lead_name), locate(%(_txt)s, lead_name), 99999),
67 if(locate(%(_txt)s, company_name), locate(%(_txt)s, company_name), 99999),
Rushabh Mehta3574b372016-03-11 14:33:04 +053068 idx desc,
Anand Doshi652bc072014-04-16 15:21:46 +053069 name, lead_name
Anand Doshi48d3b542014-07-09 13:15:03 +053070 limit %(start)s, %(page_len)s""".format(**{
71 'key': searchfield,
72 'mcond':get_match_cond(doctype)
73 }), {
74 'txt': "%%%s%%" % txt,
75 '_txt': txt.replace("%", ""),
76 'start': start,
77 'page_len': page_len
78 })
Saurabh02875592013-07-08 18:45:55 +053079
80 # searches for customer
81def customer_query(doctype, txt, searchfield, start, page_len, filters):
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053082 cust_master_name = frappe.defaults.get_user_default("cust_master_name")
Saurabhf52dc072013-07-10 13:07:49 +053083
Saurabh02875592013-07-08 18:45:55 +053084 if cust_master_name == "Customer Name":
85 fields = ["name", "customer_group", "territory"]
86 else:
87 fields = ["name", "customer_name", "customer_group", "territory"]
Saurabhf52dc072013-07-10 13:07:49 +053088
Anand Doshibd67e872014-04-11 16:51:27 +053089 fields = ", ".join(fields)
Saurabh02875592013-07-08 18:45:55 +053090
Anand Doshi48d3b542014-07-09 13:15:03 +053091 return frappe.db.sql("""select {fields} from `tabCustomer`
Anand Doshibd67e872014-04-11 16:51:27 +053092 where docstatus < 2
Anand Doshi48d3b542014-07-09 13:15:03 +053093 and ({key} like %(txt)s
shreyas29b565f2016-01-25 17:30:49 +053094 or customer_name like %(txt)s) and disabled=0
Anand Doshi48d3b542014-07-09 13:15:03 +053095 {mcond}
Anand Doshibd67e872014-04-11 16:51:27 +053096 order by
Anand Doshi48d3b542014-07-09 13:15:03 +053097 if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
98 if(locate(%(_txt)s, customer_name), locate(%(_txt)s, customer_name), 99999),
Rushabh Mehta3574b372016-03-11 14:33:04 +053099 idx desc,
Anand Doshibd67e872014-04-11 16:51:27 +0530100 name, customer_name
Anand Doshi48d3b542014-07-09 13:15:03 +0530101 limit %(start)s, %(page_len)s""".format(**{
102 "fields": fields,
103 "key": searchfield,
104 "mcond": get_match_cond(doctype)
105 }), {
106 'txt': "%%%s%%" % txt,
107 '_txt': txt.replace("%", ""),
108 'start': start,
109 'page_len': page_len
110 })
Saurabh02875592013-07-08 18:45:55 +0530111
112# searches for supplier
113def supplier_query(doctype, txt, searchfield, start, page_len, filters):
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530114 supp_master_name = frappe.defaults.get_user_default("supp_master_name")
Anand Doshibd67e872014-04-11 16:51:27 +0530115 if supp_master_name == "Supplier Name":
Saurabh02875592013-07-08 18:45:55 +0530116 fields = ["name", "supplier_type"]
Anand Doshibd67e872014-04-11 16:51:27 +0530117 else:
Saurabh02875592013-07-08 18:45:55 +0530118 fields = ["name", "supplier_name", "supplier_type"]
Anand Doshibd67e872014-04-11 16:51:27 +0530119 fields = ", ".join(fields)
Saurabh02875592013-07-08 18:45:55 +0530120
Anand Doshi48d3b542014-07-09 13:15:03 +0530121 return frappe.db.sql("""select {field} from `tabSupplier`
Anand Doshibd67e872014-04-11 16:51:27 +0530122 where docstatus < 2
Anand Doshi48d3b542014-07-09 13:15:03 +0530123 and ({key} like %(txt)s
shreyas29b565f2016-01-25 17:30:49 +0530124 or supplier_name like %(txt)s) and disabled=0
Anand Doshi48d3b542014-07-09 13:15:03 +0530125 {mcond}
Anand Doshibd67e872014-04-11 16:51:27 +0530126 order by
Anand Doshi48d3b542014-07-09 13:15:03 +0530127 if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
128 if(locate(%(_txt)s, supplier_name), locate(%(_txt)s, supplier_name), 99999),
Rushabh Mehta3574b372016-03-11 14:33:04 +0530129 idx desc,
Anand Doshibd67e872014-04-11 16:51:27 +0530130 name, supplier_name
Anand Doshi48d3b542014-07-09 13:15:03 +0530131 limit %(start)s, %(page_len)s """.format(**{
132 'field': fields,
133 'key': searchfield,
134 'mcond':get_match_cond(doctype)
135 }), {
136 'txt': "%%%s%%" % txt,
137 '_txt': txt.replace("%", ""),
138 'start': start,
139 'page_len': page_len
140 })
Anand Doshibd67e872014-04-11 16:51:27 +0530141
Nabin Hait9a380ef2013-07-16 17:24:17 +0530142def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
Anand Doshibd67e872014-04-11 16:51:27 +0530143 tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount
144 where tabAccount.docstatus!=2
Nabin Hait0c21e2a2014-03-21 11:14:49 +0530145 and account_type in (%s)
Rushabh Mehta38c6b522015-04-23 13:14:17 +0530146 and is_group = 0
Nabin Hait9a380ef2013-07-16 17:24:17 +0530147 and company = %s
148 and `%s` LIKE %s
Rushabh Mehta3574b372016-03-11 14:33:04 +0530149 order by idx desc, name
Anand Doshibd67e872014-04-11 16:51:27 +0530150 limit %s, %s""" %
151 (", ".join(['%s']*len(filters.get("account_type"))), "%s", searchfield, "%s", "%s", "%s"),
152 tuple(filters.get("account_type") + [filters.get("company"), "%%%s%%" % txt,
Nabin Hait0c21e2a2014-03-21 11:14:49 +0530153 start, page_len]))
154 if not tax_accounts:
Anand Doshibd67e872014-04-11 16:51:27 +0530155 tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount
Rushabh Mehta38c6b522015-04-23 13:14:17 +0530156 where tabAccount.docstatus!=2 and is_group = 0
Anand Doshibd67e872014-04-11 16:51:27 +0530157 and company = %s and `%s` LIKE %s limit %s, %s"""
158 % ("%s", searchfield, "%s", "%s", "%s"),
Nabin Hait0c21e2a2014-03-21 11:14:49 +0530159 (filters.get("company"), "%%%s%%" % txt, start, page_len))
Anand Doshibd67e872014-04-11 16:51:27 +0530160
Nabin Hait0c21e2a2014-03-21 11:14:49 +0530161 return tax_accounts
Saurabh02875592013-07-08 18:45:55 +0530162
163def item_query(doctype, txt, searchfield, start, page_len, filters):
164 conditions = []
Saurabhf52dc072013-07-10 13:07:49 +0530165
RicardoJohann3fb53402016-01-20 14:32:59 +0800166 return frappe.db.sql("""select tabItem.name,tabItem.item_group,
Anand Doshibd67e872014-04-11 16:51:27 +0530167 if(length(tabItem.item_name) > 40,
168 concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
Saurabh02875592013-07-08 18:45:55 +0530169 if(length(tabItem.description) > 40, \
Anand Doshi22c0d782013-11-04 16:23:04 +0530170 concat(substr(tabItem.description, 1, 40), "..."), description) as decription
Anand Doshibd67e872014-04-11 16:51:27 +0530171 from tabItem
Anand Doshi22c0d782013-11-04 16:23:04 +0530172 where tabItem.docstatus < 2
Anand Doshi602e8252015-11-16 19:05:46 +0530173 and tabItem.has_variants=0
Anand Doshi21e09a22015-10-29 12:21:41 +0530174 and tabItem.disabled=0
Rushabh Mehta864d1ea2014-06-23 12:20:12 +0530175 and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
Anand Doshi22c0d782013-11-04 16:23:04 +0530176 and (tabItem.`{key}` LIKE %(txt)s
ShashaQin425ab6b2016-03-02 13:07:58 +0800177 or tabItem.item_group LIKE %(txt)s
Anand Doshi7fcb3c92014-07-21 17:51:14 +0530178 or tabItem.item_name LIKE %(txt)s
179 or tabItem.description LIKE %(txt)s)
Anand Doshi22c0d782013-11-04 16:23:04 +0530180 {fcond} {mcond}
Anand Doshi652bc072014-04-16 15:21:46 +0530181 order by
182 if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
183 if(locate(%(_txt)s, item_name), locate(%(_txt)s, item_name), 99999),
Rushabh Mehta3574b372016-03-11 14:33:04 +0530184 idx desc,
Anand Doshi652bc072014-04-16 15:21:46 +0530185 name, item_name
Anand Doshi22c0d782013-11-04 16:23:04 +0530186 limit %(start)s, %(page_len)s """.format(key=searchfield,
187 fcond=get_filters_cond(doctype, filters, conditions),
Anand Doshibd67e872014-04-11 16:51:27 +0530188 mcond=get_match_cond(doctype)),
Anand Doshi22c0d782013-11-04 16:23:04 +0530189 {
190 "today": nowdate(),
191 "txt": "%%%s%%" % txt,
Anand Doshi652bc072014-04-16 15:21:46 +0530192 "_txt": txt.replace("%", ""),
Anand Doshi22c0d782013-11-04 16:23:04 +0530193 "start": start,
194 "page_len": page_len
195 })
Saurabh02875592013-07-08 18:45:55 +0530196
197def bom(doctype, txt, searchfield, start, page_len, filters):
Anand Doshibd67e872014-04-11 16:51:27 +0530198 conditions = []
Saurabhf52dc072013-07-10 13:07:49 +0530199
Anand Doshibd67e872014-04-11 16:51:27 +0530200 return frappe.db.sql("""select tabBOM.name, tabBOM.item
201 from tabBOM
202 where tabBOM.docstatus=1
203 and tabBOM.is_active=1
Nabin Hait62211172016-03-16 16:22:03 +0530204 and tabBOM.`{key}` like %(txt)s
205 {fcond} {mcond}
206 order by
Rushabh Mehta3574b372016-03-11 14:33:04 +0530207 if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
208 idx desc, name
Nabin Hait62211172016-03-16 16:22:03 +0530209 limit %(start)s, %(page_len)s """.format(
210 fcond=get_filters_cond(doctype, filters, conditions),
211 mcond=get_match_cond(doctype),
212 key=frappe.db.escape(searchfield)),
213 {
Rushabh Mehta3574b372016-03-11 14:33:04 +0530214 'txt': "%%%s%%" % frappe.db.escape(txt),
215 '_txt': txt.replace("%", ""),
Nabin Hait62211172016-03-16 16:22:03 +0530216 'start': start,
217 'page_len': page_len
Rushabh Mehta3574b372016-03-11 14:33:04 +0530218 })
Saurabh02875592013-07-08 18:45:55 +0530219
Saurabh02875592013-07-08 18:45:55 +0530220def get_project_name(doctype, txt, searchfield, start, page_len, filters):
221 cond = ''
Nabin Haitf71011a2014-08-21 11:34:31 +0530222 if filters.get('customer'):
Saurabhab462d22013-07-09 16:18:52 +0530223 cond = '(`tabProject`.customer = "' + filters['customer'] + '" or ifnull(`tabProject`.customer,"")="") and'
Anand Doshibd67e872014-04-11 16:51:27 +0530224
225 return frappe.db.sql("""select `tabProject`.name from `tabProject`
226 where `tabProject`.status not in ("Completed", "Cancelled")
Rushabh Mehta3574b372016-03-11 14:33:04 +0530227 and {cond} `tabProject`.name like %(txt)s {match_cond}
228 order by
229 if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
230 idx desc,
231 `tabProject`.name asc
232 limit {start}, {page_len}""".format(
233 cond=cond,
234 match_cond=get_match_cond(doctype),
235 start=start,
236 page_len=page_len), {
237 "txt": "%{0}%".format(txt),
Nabin Haitdf4deba2016-03-16 11:16:31 +0530238 "_txt": txt.replace('%', '')
Rushabh Mehta3574b372016-03-11 14:33:04 +0530239 })
Anand Doshibd67e872014-04-11 16:51:27 +0530240
Anand Doshi17350b82013-08-01 15:45:23 +0530241def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, filters):
Anand Doshie9baaa62014-02-26 12:35:33 +0530242 return frappe.db.sql("""select `tabDelivery Note`.name, `tabDelivery Note`.customer_name
Anand Doshibd67e872014-04-11 16:51:27 +0530243 from `tabDelivery Note`
244 where `tabDelivery Note`.`%(key)s` like %(txt)s and
shreyas29b565f2016-01-25 17:30:49 +0530245 `tabDelivery Note`.docstatus = 1 and status not in ("Stopped", "Closed") %(fcond)s
shreyas2563f402016-01-25 17:44:09 +0530246 and (`tabDelivery Note`.per_billed < 100 or `tabDelivery Note`.grand_total = 0)
Anand Doshi17350b82013-08-01 15:45:23 +0530247 %(mcond)s order by `tabDelivery Note`.`%(key)s` asc
248 limit %(start)s, %(page_len)s""" % {
249 "key": searchfield,
250 "fcond": get_filters_cond(doctype, filters, []),
251 "mcond": get_match_cond(doctype),
252 "start": "%(start)s", "page_len": "%(page_len)s", "txt": "%(txt)s"
Nabin Haitd1fd1e22013-10-18 12:29:11 +0530253 }, { "start": start, "page_len": page_len, "txt": ("%%%s%%" % txt) })
254
255def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
Neil Trini Lasradoebb60f52015-07-08 14:36:09 +0530256 cond = ""
257 if filters.get("posting_date"):
258 cond = "and (ifnull(batch.expiry_date, '')='' or batch.expiry_date >= %(posting_date)s)"
Rushabh Mehtab6398be2015-08-26 10:50:16 +0530259
Nabin Hait2ed71ba2015-03-20 15:06:30 +0530260 batch_nos = None
261 args = {
262 'item_code': filters.get("item_code"),
263 'warehouse': filters.get("warehouse"),
264 'posting_date': filters.get('posting_date'),
Anand Doshi0dc79f42015-04-06 12:59:34 +0530265 'txt': "%{0}%".format(txt),
Nabin Hait2ed71ba2015-03-20 15:06:30 +0530266 "start": start,
267 "page_len": page_len
268 }
269
Anand Doshi0dc79f42015-04-06 12:59:34 +0530270 if args.get('warehouse'):
271 batch_nos = frappe.db.sql("""select sle.batch_no, round(sum(sle.actual_qty),2), sle.stock_uom, batch.expiry_date
272 from `tabStock Ledger Entry` sle
273 INNER JOIN `tabBatch` batch on sle.batch_no = batch.name
274 where
275 sle.item_code = %(item_code)s
276 and sle.warehouse = %(warehouse)s
277 and sle.batch_no like %(txt)s
278 and batch.docstatus < 2
Neil Trini Lasradoebb60f52015-07-08 14:36:09 +0530279 {0}
Anand Doshi0dc79f42015-04-06 12:59:34 +0530280 {match_conditions}
281 group by batch_no having sum(sle.actual_qty) > 0
282 order by batch.expiry_date, sle.batch_no desc
Neil Trini Lasradoebb60f52015-07-08 14:36:09 +0530283 limit %(start)s, %(page_len)s""".format(cond, match_conditions=get_match_cond(doctype)), args)
Nabin Hait2ed71ba2015-03-20 15:06:30 +0530284
285 if batch_nos:
286 return batch_nos
Nabin Haitd1fd1e22013-10-18 12:29:11 +0530287 else:
Neil Trini Lasradoebb60f52015-07-08 14:36:09 +0530288 return frappe.db.sql("""select name, expiry_date from `tabBatch` batch
Anand Doshi0dc79f42015-04-06 12:59:34 +0530289 where item = %(item_code)s
290 and name like %(txt)s
Nabin Hait2ed71ba2015-03-20 15:06:30 +0530291 and docstatus < 2
Neil Trini Lasradoebb60f52015-07-08 14:36:09 +0530292 {0}
Anand Doshi0dc79f42015-04-06 12:59:34 +0530293 {match_conditions}
294 order by expiry_date, name desc
Nabin Haite52ee552015-09-02 10:55:32 +0530295 limit %(start)s, %(page_len)s""".format(cond, match_conditions=get_match_cond(doctype)), args)
Nabin Haitea4aa042014-05-28 12:56:28 +0530296
297def get_account_list(doctype, txt, searchfield, start, page_len, filters):
Nabin Haite1b2b3e2014-06-14 15:26:10 +0530298 filter_list = []
Nabin Haitea4aa042014-05-28 12:56:28 +0530299
Nabin Haite1b2b3e2014-06-14 15:26:10 +0530300 if isinstance(filters, dict):
301 for key, val in filters.items():
302 if isinstance(val, (list, tuple)):
303 filter_list.append([doctype, key, val[0], val[1]])
304 else:
305 filter_list.append([doctype, key, "=", val])
bhupeshg2e2e973f2015-04-14 22:15:24 +0530306 elif isinstance(filters, list):
307 filter_list.extend(filters)
Nabin Haite1b2b3e2014-06-14 15:26:10 +0530308
Rushabh Mehta38c6b522015-04-23 13:14:17 +0530309 if "is_group" not in [d[1] for d in filter_list]:
310 filter_list.append(["Account", "is_group", "=", "0"])
Nabin Haite1b2b3e2014-06-14 15:26:10 +0530311
312 if searchfield and txt:
313 filter_list.append([doctype, searchfield, "like", "%%%s%%" % txt])
314
Rushabh Mehtac0bb4532014-09-09 16:15:35 +0530315 return frappe.desk.reportview.execute("Account", filters = filter_list,
Nabin Haitea4aa042014-05-28 12:56:28 +0530316 fields = ["name", "parent_account"],
317 limit_start=start, limit_page_length=page_len, as_list=True)
Anand Doshifaefeaa2014-06-24 18:53:04 +0530318
Nabin Haitafd14f62015-10-19 11:55:28 +0530319
320@frappe.whitelist()
321def get_income_account(doctype, txt, searchfield, start, page_len, filters):
322 from erpnext.controllers.queries import get_match_cond
323
324 # income account can be any Credit account,
325 # but can also be a Asset account with account_type='Income Account' in special circumstances.
326 # Hence the first condition is an "OR"
327 if not filters: filters = {}
328
Anand Doshi21e09a22015-10-29 12:21:41 +0530329 condition = ""
Nabin Haitafd14f62015-10-19 11:55:28 +0530330 if filters.get("company"):
331 condition += "and tabAccount.company = %(company)s"
Anand Doshi21e09a22015-10-29 12:21:41 +0530332
Nabin Haitafd14f62015-10-19 11:55:28 +0530333 return frappe.db.sql("""select tabAccount.name from `tabAccount`
334 where (tabAccount.report_type = "Profit and Loss"
335 or tabAccount.account_type in ("Income Account", "Temporary"))
336 and tabAccount.is_group=0
337 and tabAccount.`{key}` LIKE %(txt)s
Rushabh Mehta3574b372016-03-11 14:33:04 +0530338 {condition} {match_condition}
339 order by idx desc, name"""
Nabin Haitafd14f62015-10-19 11:55:28 +0530340 .format(condition=condition, match_condition=get_match_cond(doctype), key=searchfield), {
Anand Doshi21e09a22015-10-29 12:21:41 +0530341 'txt': "%%%s%%" % frappe.db.escape(txt),
Nabin Haitafd14f62015-10-19 11:55:28 +0530342 'company': filters.get("company", "")
Anand Doshi21e09a22015-10-29 12:21:41 +0530343 })