Fixes in Filter conditions in reportview to handle null valuesversion-14
@@ -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]; | ||||
@@ -178,6 +178,7 @@ wn.views.QueryReport = Class.extend({ | |||||
var mandatory_fields = []; | var mandatory_fields = []; | ||||
$.each(this.filters || [], function(i, f) { | $.each(this.filters || [], function(i, f) { | ||||
var v = f.get_parsed_value(); | var v = f.get_parsed_value(); | ||||
if(v === '%') v = null; | |||||
if(f.df.reqd && !v) mandatory_fields.push(f.df.label); | if(f.df.reqd && !v) mandatory_fields.push(f.df.label); | ||||
if(v) filters[f.df.fieldname] = v; | if(v) filters[f.df.fieldname] = v; | ||||
}) | }) | ||||
@@ -344,6 +344,7 @@ class Bean: | |||||
if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc): | if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc): | ||||
self.to_docstatus = 1 | self.to_docstatus = 1 | ||||
self.prepare_for_save("update_after_submit") | self.prepare_for_save("update_after_submit") | ||||
self.run_method('validate') | |||||
self.run_method('before_update_after_submit') | self.run_method('before_update_after_submit') | ||||
self.save_main() | self.save_main() | ||||
self.save_children() | self.save_children() | ||||
@@ -78,7 +78,7 @@ def run(report_name, filters=None): | |||||
module = webnotes.conn.get_value("DocType", report.ref_doctype, "module") | module = webnotes.conn.get_value("DocType", report.ref_doctype, "module") | ||||
if report.is_standard=="Yes": | if report.is_standard=="Yes": | ||||
method_name = scrub(module) + ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute" | 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: | else: | ||||
namespace = get_code_and_execute(module, "Report", report.name) | namespace = get_code_and_execute(module, "Report", report.name) | ||||
columns, result = namespace["execute"](filters or {}) | columns, result = namespace["execute"](filters or {}) | ||||
@@ -160,10 +160,11 @@ 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) | ||||
@@ -176,14 +177,22 @@ 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): | if isinstance(f[3], basestring): | ||||
f[3] = "'" + f[3].replace("'", "\\'") + "'" | |||||
conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3]) | |||||
df = webnotes.local.reportview_doctypes[f[0]].get({"doctype": "DocField", | |||||
"fieldname": f[1]}) | |||||
if df and df[0].fieldtype in ["Float", "Int", "Currency", "Percent"]: | |||||
val, default_null_val = flt(f[3]), 0 | |||||
else: | |||||
val, default_null_val = ("'" + f[3].replace("'", "\\'") + "'"), "" | |||||
else: | 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): | def build_match_conditions(doctype, fields=None, as_condition=True): | ||||
"""add match conditions if applicable""" | """add match conditions if applicable""" | ||||