From df62a9fc1aa24b73519ddc5caacee3f3bd0cca92 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 25 Dec 2013 12:29:48 +0530 Subject: [PATCH 1/5] Fixes in Filter conditions in reportview to handle null values --- public/js/wn/ui/filters.js | 2 +- webnotes/widgets/reportview.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/public/js/wn/ui/filters.js b/public/js/wn/ui/filters.js index 195589d90f..15735782ce 100644 --- a/public/js/wn/ui/filters.js +++ b/public/js/wn/ui/filters.js @@ -272,7 +272,7 @@ wn.ui.Filter = Class.extend({ if ((val.length === 0) || (val.lastIndexOf("%") !== (val.length - 1))) { val = (val || "") + '%'; } - } + } else if(val === '%') val = null; return [me.fieldselect.$select.find('option:selected').attr('table'), me.field.df.fieldname, me.$w.find('.condition').val(), val]; diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index 5b04cb604b..99b9098a6a 100644 --- a/webnotes/widgets/reportview.py +++ b/webnotes/widgets/reportview.py @@ -160,14 +160,18 @@ def build_conditions(doctype, fields, filters, docstatus): def build_filter_conditions(filters, conditions): """build conditions from user filters""" - from webnotes.utils import cstr + from webnotes.utils import cstr, flt if not getattr(webnotes.local, "reportview_tables", None): webnotes.local.reportview_tables = [] - + + doclist = {} for f in filters: if isinstance(f, basestring): conditions.append(f) else: + # get doclist of given doctype + doclist.setdefault(f[0], webnotes.model.doctype.get(f[0])) + tname = ('`tab' + f[0] + '`') if not tname in webnotes.local.reportview_tables: webnotes.local.reportview_tables.append(tname) @@ -176,14 +180,18 @@ def build_filter_conditions(filters, conditions): 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]) + conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + " " + f[3]) else: - if isinstance(f[3], basestring): - f[3] = "'" + f[3].replace("'", "\\'") + "'" - conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3]) + fieldtype = doclist[f[0]].get({"doctype": "DocField", + "fieldname": f[1]})[0].fieldtype + if fieldtype in ["Float", "Int", "Currency", "Percent"]: + conditions.append('ifnull(' + tname + '.' + f[1] + ", 0) " + f[2] \ + + " " + cstr(flt(f[3]))) else: - conditions.append('ifnull(' + tname + '.' + f[1] + ",0) " + f[2] \ - + " " + cstr(f[3])) + f[3] = "'" + f[3].replace("'", "\\'") + "'" + conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + \ + " " + cstr(f[3])) + def build_match_conditions(doctype, fields=None, as_condition=True): """add match conditions if applicable""" From 3feaa9fd4342ffc16bc22908dc43c3d8c59183d6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 25 Dec 2013 14:21:45 +0530 Subject: [PATCH 2/5] Fixes in Filter conditions in reportview to handle null values --- webnotes/widgets/reportview.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index 99b9098a6a..e176e3cc80 100644 --- a/webnotes/widgets/reportview.py +++ b/webnotes/widgets/reportview.py @@ -182,15 +182,20 @@ def build_filter_conditions(filters, conditions): f[3] = "(" + ', '.join(opts) + ")" conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + " " + f[3]) else: - fieldtype = doclist[f[0]].get({"doctype": "DocField", - "fieldname": f[1]})[0].fieldtype - if fieldtype in ["Float", "Int", "Currency", "Percent"]: - conditions.append('ifnull(' + tname + '.' + f[1] + ", 0) " + f[2] \ - + " " + cstr(flt(f[3]))) + if isinstance(f[3], basestring): + docfield = doclist[f[0]].get({"doctype": "DocField", "fieldname": f[1]}) + + if docfield and docfield[0].fieldtype in ["Float", + "Int", "Currency", "Percent"]: + conditions.append('ifnull(' + tname + '.' + f[1] + ", 0) " + f[2] \ + + " " + cstr(flt(f[3]))) + else: + f[3] = "'" + f[3].replace("'", "\\'") + "'" + conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + \ + " " + cstr(f[3])) else: - f[3] = "'" + f[3].replace("'", "\\'") + "'" - conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + \ - " " + cstr(f[3])) + conditions.append('ifnull(' + tname + '.' + f[1] + ", 0) " + f[2] \ + + " " + cstr(f[3])) def build_match_conditions(doctype, fields=None, as_condition=True): From 19d375a20b27cbcabf1046a255e50f3bc90d8445 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 27 Dec 2013 17:38:16 +0530 Subject: [PATCH 3/5] Call validate form update_after_submit --- webnotes/model/bean.py | 1 + 1 file changed, 1 insertion(+) diff --git a/webnotes/model/bean.py b/webnotes/model/bean.py index dde95edc40..fbd749214f 100644 --- a/webnotes/model/bean.py +++ b/webnotes/model/bean.py @@ -344,6 +344,7 @@ class Bean: if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc): self.to_docstatus = 1 self.prepare_for_save("update_after_submit") + self.run_method('validate') self.run_method('before_update_after_submit') self.save_main() self.save_children() From b83cd0291e87e1066664ac96583114067aee7c6e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 27 Dec 2013 17:38:46 +0530 Subject: [PATCH 4/5] Small fixes in query report --- public/js/wn/views/query_report.js | 1 + webnotes/widgets/query_report.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/public/js/wn/views/query_report.js b/public/js/wn/views/query_report.js index 5905665734..2626529bb0 100644 --- a/public/js/wn/views/query_report.js +++ b/public/js/wn/views/query_report.js @@ -178,6 +178,7 @@ wn.views.QueryReport = Class.extend({ var mandatory_fields = []; $.each(this.filters || [], function(i, f) { var v = f.get_parsed_value(); + if(v === '%') v = null; if(f.df.reqd && !v) mandatory_fields.push(f.df.label); if(v) filters[f.df.fieldname] = v; }) diff --git a/webnotes/widgets/query_report.py b/webnotes/widgets/query_report.py index deb355ec4c..7e29bfa463 100644 --- a/webnotes/widgets/query_report.py +++ b/webnotes/widgets/query_report.py @@ -78,7 +78,7 @@ def run(report_name, filters=None): module = webnotes.conn.get_value("DocType", report.ref_doctype, "module") if report.is_standard=="Yes": method_name = scrub(module) + ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute" - columns, result = webnotes.get_method(method_name)(filters or {}) + columns, result = webnotes.get_method(method_name)(webnotes._dict(filters)) else: namespace = get_code_and_execute(module, "Report", report.name) columns, result = namespace["execute"](filters or {}) From a701dd947254b874d5c445abb4b6a8c0e8adf24f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 27 Dec 2013 18:06:33 +0530 Subject: [PATCH 5/5] Fixes in filter_conditions, null issue --- webnotes/widgets/reportview.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index e176e3cc80..38034a74ee 100644 --- a/webnotes/widgets/reportview.py +++ b/webnotes/widgets/reportview.py @@ -169,9 +169,6 @@ def build_filter_conditions(filters, conditions): if isinstance(f, basestring): conditions.append(f) else: - # get doclist of given doctype - doclist.setdefault(f[0], webnotes.model.doctype.get(f[0])) - tname = ('`tab' + f[0] + '`') if not tname in webnotes.local.reportview_tables: webnotes.local.reportview_tables.append(tname) @@ -183,19 +180,18 @@ def build_filter_conditions(filters, conditions): conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + " " + f[3]) else: if isinstance(f[3], basestring): - docfield = doclist[f[0]].get({"doctype": "DocField", "fieldname": f[1]}) + df = webnotes.local.reportview_doctypes[f[0]].get({"doctype": "DocField", + "fieldname": f[1]}) - if docfield and docfield[0].fieldtype in ["Float", - "Int", "Currency", "Percent"]: - conditions.append('ifnull(' + tname + '.' + f[1] + ", 0) " + f[2] \ - + " " + cstr(flt(f[3]))) + if df and df[0].fieldtype in ["Float", "Int", "Currency", "Percent"]: + val, default_null_val = flt(f[3]), 0 else: - f[3] = "'" + f[3].replace("'", "\\'") + "'" - conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + \ - " " + cstr(f[3])) + val, default_null_val = ("'" + f[3].replace("'", "\\'") + "'"), "" else: - conditions.append('ifnull(' + tname + '.' + f[1] + ", 0) " + f[2] \ - + " " + cstr(f[3])) + val, default_null_val = f[3], 0 + + conditions.append('ifnull(' + tname + '.' + f[1] + ", '"+ default_null_val +"') " \ + + f[2] + " " + cstr(val)) def build_match_conditions(doctype, fields=None, as_condition=True):