diff --git a/core/doctype/communication/communication.js b/core/doctype/communication/communication.js index 640b2ad902..f418333a87 100644 --- a/core/doctype/communication/communication.js +++ b/core/doctype/communication/communication.js @@ -1,22 +1,21 @@ cur_frm.cscript.onload = function(doc) { cur_frm.fields_dict.user.get_query = function() { - return "select name, concat_ws(' ', first_name, middle_name, last_name) \ - from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \ - (%(key)s like \"%s\" or \ - concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \ - limit 50"; + return { + query: "core.doctype.communication.communication.get_user" + } }; cur_frm.fields_dict.lead.get_query = function() { - return "select name, lead_name from `tabLead` \ - where docstatus < 2 and \ - (%(key)s like \"%s\" or lead_name like \"%%%s\" or \ - company_name like \"%%%s\") \ - order by lead_name asc limit 50"; + return { + query: "core.doctype.communication.communication.get_user" + } }; - cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; - cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query; + cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.customer_query" } } + + cur_frm.fields_dict.supplier.get_query = function(doc,cdt,cdn) { + return{ query:"controllers.queries.supplier_query" } } if(doc.content) doc.content = wn.utils.escape_script_and_style(doc.content); diff --git a/core/doctype/communication/communication.py b/core/doctype/communication/communication.py index c24330bbb7..79b7d5bb41 100644 --- a/core/doctype/communication/communication.py +++ b/core/doctype/communication/communication.py @@ -119,3 +119,29 @@ class DocType(): def __init__(self, doc, doclist=[]): self.doc = doc self.doclist = doclist + +def get_user(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + return webnotes.conn.sql("""select name, concat_ws(' ', first_name, middle_name, last_name) + from `tabProfile` + where ifnull(enabled, 0)=1 + and docstatus < 2 + and (%(key)s like "%(txt)s" + or concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s") + %(mcond)s + limit %(start)s, %(page_len)s """ % {'key': searchfield, + 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), + 'start': start, 'page_len': page_len}) + +def get_lead(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + return webnotes.conn.sql(""" select name, lead_name from `tabLead` + where docstatus < 2 + and (%(key)s like "%(txt)s" + or lead_name like "%(txt)s" + or company_name like "%(txt)s") + %(mcond)s + order by lead_name asc + limit %(start)s, %(page_len)s """ % {'key': searchfield,'txt': "%%%s%%" % txt, + 'mcond':get_match_cond(doctype, searchfield), 'start': start, + 'page_len': page_len}) \ No newline at end of file diff --git a/core/doctype/custom_field/custom_field.js b/core/doctype/custom_field/custom_field.js index e122339fcb..e27a4480ce 100644 --- a/core/doctype/custom_field/custom_field.js +++ b/core/doctype/custom_field/custom_field.js @@ -55,10 +55,12 @@ cur_frm.cscript.label = function(doc){ cur_frm.fields_dict['dt'].get_query = function(doc, dt, dn) { - return 'SELECT name FROM `tabDocType` \ - WHERE IFNULL(issingle,0)=0 AND \ - module != "Core" AND \ - name LIKE "%s%%" ORDER BY name ASC LIMIT 50'; + return{ + filters:[ + ['DocType', 'issingle', '=', 0], + ['DocType', 'module', '!=', 'Core'] + ] + } } cur_frm.cscript.fieldtype = function(doc, dt, dn) { diff --git a/core/doctype/customize_form/customize_form.js b/core/doctype/customize_form/customize_form.js index 602ee04afd..8ac191ee7b 100644 --- a/core/doctype/customize_form/customize_form.js +++ b/core/doctype/customize_form/customize_form.js @@ -42,13 +42,14 @@ cur_frm.cscript.onload = function(doc, dt, dn) { } cur_frm.fields_dict.doc_type.get_query = function(doc, dt, dn) { - return 'SELECT name FROM `tabDocType` \ - WHERE ((IFNULL(issingle,0)=0 AND \ - IFNULL(in_create, 0)=0 AND \ - name not in ("DocType", "DocField", "DocPerm", "Profile", "Role", "UserRole", "Page", \ - "Page Role", "Module Def", "Print Format", "Report")) \ - or name = "Item Group") \ - AND name LIKE "%s%%" ORDER BY name ASC LIMIT 50'; + return{ + filters:[ + ['DocType', 'issingle', '=', 0], + ['DocType', 'in_create', '=', 0], + ['DocType', 'name', 'not in', 'DocType, DocField, DocPerm, Profile, Role, UserRole,\ + Page, Page Role, Module Def, Print Format, Report'] + ] + } } cur_frm.cscript.refresh = function(doc, dt, dn) { diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index 0e710f3cc1..7c22ed36fc 100644 --- a/webnotes/widgets/reportview.py +++ b/webnotes/widgets/reportview.py @@ -172,6 +172,8 @@ def build_conditions(doctype, fields, filters, docstatus): def build_filter_conditions(filters, conditions): """build conditions from user filters""" from webnotes.utils import cstr + global tables + if not tables: tables = [] for f in filters: if isinstance(f, basestring): @@ -182,7 +184,7 @@ def build_filter_conditions(filters, conditions): tables.append(tname) # prepare in condition - if f[2]=='in': + if f[2] in ['in', 'not in']: opts = ["'" + t.strip().replace("'", "\\'") + "'" for t in f[3].split(',')] f[3] = "(" + ', '.join(opts) + ")" conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3])