Преглед изворни кода

Fixes in Filter conditions in reportview to handle null values

version-14
Nabin Hait пре 11 година
родитељ
комит
df62a9fc1a
2 измењених фајлова са 17 додато и 9 уклоњено
  1. +1
    -1
      public/js/wn/ui/filters.js
  2. +16
    -8
      webnotes/widgets/reportview.py

+ 1
- 1
public/js/wn/ui/filters.js Прегледај датотеку

@@ -272,7 +272,7 @@ wn.ui.Filter = Class.extend({
if ((val.length === 0) || (val.lastIndexOf("%") !== (val.length - 1))) { if ((val.length === 0) || (val.lastIndexOf("%") !== (val.length - 1))) {
val = (val || "") + '%'; val = (val || "") + '%';
} }
}
} else if(val === '%') val = null;
return [me.fieldselect.$select.find('option:selected').attr('table'), return [me.fieldselect.$select.find('option:selected').attr('table'),
me.field.df.fieldname, me.$w.find('.condition').val(), val]; me.field.df.fieldname, me.$w.find('.condition').val(), val];


+ 16
- 8
webnotes/widgets/reportview.py Прегледај датотеку

@@ -160,14 +160,18 @@ def build_conditions(doctype, fields, filters, docstatus):
def build_filter_conditions(filters, conditions): def build_filter_conditions(filters, conditions):
"""build conditions from user filters""" """build conditions from user filters"""
from webnotes.utils import cstr
from webnotes.utils import cstr, flt
if not getattr(webnotes.local, "reportview_tables", None): if not getattr(webnotes.local, "reportview_tables", None):
webnotes.local.reportview_tables = [] webnotes.local.reportview_tables = []
doclist = {}
for f in filters: for f in filters:
if isinstance(f, basestring): if isinstance(f, basestring):
conditions.append(f) conditions.append(f)
else: else:
# get doclist of given doctype
doclist.setdefault(f[0], webnotes.model.doctype.get(f[0]))
tname = ('`tab' + f[0] + '`') tname = ('`tab' + f[0] + '`')
if not tname in webnotes.local.reportview_tables: if not tname in webnotes.local.reportview_tables:
webnotes.local.reportview_tables.append(tname) webnotes.local.reportview_tables.append(tname)
@@ -176,14 +180,18 @@ def build_filter_conditions(filters, conditions):
if f[2] in ['in', 'not in']: if f[2] in ['in', 'not in']:
opts = ["'" + t.strip().replace("'", "\\'") + "'" for t in f[3].split(',')] opts = ["'" + t.strip().replace("'", "\\'") + "'" for t in f[3].split(',')]
f[3] = "(" + ', '.join(opts) + ")" f[3] = "(" + ', '.join(opts) + ")"
conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3])
conditions.append('ifnull(' + tname + '.' + f[1] + ", '') " + f[2] + " " + f[3])
else: 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: 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): def build_match_conditions(doctype, fields=None, as_condition=True):
"""add match conditions if applicable""" """add match conditions if applicable"""


Loading…
Откажи
Сачувај