From e487b1a37d82cbe0aa72c235fafa751eb15f195e Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 9 Jul 2013 10:10:43 +0530 Subject: [PATCH 1/4] changes to handle server side queries --- webnotes/widgets/reportview.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index 8b35e0d6b0..e99d6d3972 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: tname = ('`tab' + f[0] + '`') @@ -179,7 +181,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]) From f69207e243f0753b9b493d21a400afd8fdbd8079 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 9 Jul 2013 16:19:49 +0530 Subject: [PATCH 2/4] [get_query]to server side --- core/doctype/communication/communication.js | 23 +++++++++---------- core/doctype/communication/communication.py | 20 ++++++++++++++++ core/doctype/custom_field/custom_field.js | 14 +++++++---- core/doctype/customize_form/customize_form.js | 22 ++++++++++++------ 4 files changed, 56 insertions(+), 23 deletions(-) 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..ff4b050f2e 100644 --- a/core/doctype/communication/communication.py +++ b/core/doctype/communication/communication.py @@ -119,3 +119,23 @@ 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..ee02ae8549 100644 --- a/core/doctype/custom_field/custom_field.js +++ b/core/doctype/custom_field/custom_field.js @@ -55,10 +55,16 @@ 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'] + ] + } + // return 'SELECT name FROM `tabDocType` \ + // WHERE IFNULL(issingle,0)=0 AND \ + // module != "Core" AND \ + // name LIKE "%s%%" ORDER BY name ASC LIMIT 50'; } 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 ac60263552..a1db4a0ae3 100644 --- a/core/doctype/customize_form/customize_form.js +++ b/core/doctype/customize_form/customize_form.js @@ -36,13 +36,21 @@ 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'] + ] + } + // 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'; } cur_frm.cscript.refresh = function(doc, dt, dn) { From 8f7dbbd2f28dcae15a62577247e206fc56f45339 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 9 Jul 2013 18:21:36 +0530 Subject: [PATCH 3/4] [get_query]to server side --- core/doctype/custom_field/custom_field.js | 4 ---- core/doctype/customize_form/customize_form.js | 7 ------- 2 files changed, 11 deletions(-) diff --git a/core/doctype/custom_field/custom_field.js b/core/doctype/custom_field/custom_field.js index ee02ae8549..e27a4480ce 100644 --- a/core/doctype/custom_field/custom_field.js +++ b/core/doctype/custom_field/custom_field.js @@ -61,10 +61,6 @@ cur_frm.fields_dict['dt'].get_query = function(doc, dt, dn) { ['DocType', 'module', '!=', 'Core'] ] } - // return 'SELECT name FROM `tabDocType` \ - // WHERE IFNULL(issingle,0)=0 AND \ - // module != "Core" AND \ - // name LIKE "%s%%" ORDER BY name ASC LIMIT 50'; } 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 ddfa1ef3c1..8ac191ee7b 100644 --- a/core/doctype/customize_form/customize_form.js +++ b/core/doctype/customize_form/customize_form.js @@ -50,13 +50,6 @@ cur_frm.fields_dict.doc_type.get_query = function(doc, dt, dn) { Page, Page Role, Module Def, Print Format, Report'] ] } - // 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'; } cur_frm.cscript.refresh = function(doc, dt, dn) { From fe4561c54a55178c2aa3d0a5a952553ee165f396 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 10 Jul 2013 17:40:03 +0530 Subject: [PATCH 4/4] get_query to server side --- core/doctype/communication/communication.py | 26 +++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/core/doctype/communication/communication.py b/core/doctype/communication/communication.py index ff4b050f2e..79b7d5bb41 100644 --- a/core/doctype/communication/communication.py +++ b/core/doctype/communication/communication.py @@ -123,19 +123,25 @@ class DocType(): 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, + 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 + 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