From a701dd947254b874d5c445abb4b6a8c0e8adf24f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 27 Dec 2013 18:06:33 +0530 Subject: [PATCH] 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):