|
|
@@ -160,10 +160,11 @@ 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) |
|
|
@@ -176,14 +177,22 @@ 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]) |
|
|
|
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: |
|
|
|
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): |
|
|
|
"""add match conditions if applicable""" |
|
|
|