fix: Use separate condition for tree and normal doctype
This commit is contained in:
parent
96dd2079f3
commit
62e9f83aab
@ -193,7 +193,7 @@ def get_dimension_with_children(doctype, dimension):
|
|||||||
|
|
||||||
all_dimensions = []
|
all_dimensions = []
|
||||||
lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
|
||||||
children = frappe.get_all(doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
|
children = frappe.get_all(doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, order_by="lft")
|
||||||
all_dimensions += [c.name for c in children]
|
all_dimensions += [c.name for c in children]
|
||||||
|
|
||||||
return all_dimensions
|
return all_dimensions
|
||||||
|
@ -420,6 +420,8 @@ def get_additional_conditions(from_date, ignore_closing_entries, filters):
|
|||||||
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
||||||
filters.get(dimension.fieldname))
|
filters.get(dimension.fieldname))
|
||||||
additional_conditions.append("{0} in %({0})s".format(dimension.fieldname))
|
additional_conditions.append("{0} in %({0})s".format(dimension.fieldname))
|
||||||
|
else:
|
||||||
|
additional_conditions.append("{0} in (%({0})s)".format(dimension.fieldname))
|
||||||
|
|
||||||
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
|
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
|
||||||
|
|
||||||
|
@ -203,6 +203,8 @@ def get_conditions(filters):
|
|||||||
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
||||||
filters.get(dimension.fieldname))
|
filters.get(dimension.fieldname))
|
||||||
conditions.append("{0} in %({0})s".format(dimension.fieldname))
|
conditions.append("{0} in %({0})s".format(dimension.fieldname))
|
||||||
|
else:
|
||||||
|
conditions.append("{0} in (%({0})s)".format(dimension.fieldname))
|
||||||
|
|
||||||
return "and {}".format(" and ".join(conditions)) if conditions else ""
|
return "and {}".format(" and ".join(conditions)) if conditions else ""
|
||||||
|
|
||||||
|
@ -344,16 +344,19 @@ def get_conditions(filters):
|
|||||||
accounting_dimensions = get_accounting_dimensions(as_list=False)
|
accounting_dimensions = get_accounting_dimensions(as_list=False)
|
||||||
|
|
||||||
if accounting_dimensions:
|
if accounting_dimensions:
|
||||||
|
common_condition = """
|
||||||
|
and exists(select name from `tabSales Invoice Item`
|
||||||
|
where parent=`tabSales Invoice`.name
|
||||||
|
"""
|
||||||
for dimension in accounting_dimensions:
|
for dimension in accounting_dimensions:
|
||||||
if filters.get(dimension.fieldname):
|
if filters.get(dimension.fieldname):
|
||||||
if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
|
if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
|
||||||
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
||||||
filters.get(dimension.fieldname))
|
filters.get(dimension.fieldname))
|
||||||
|
|
||||||
conditions += """ and exists(select name from `tabSales Invoice Item`
|
conditions += common_condition + "and ifnull(`tabSales Invoice Item`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||||
where parent=`tabSales Invoice`.name
|
else:
|
||||||
and ifnull(`tabSales Invoice Item`.{0}, '') in %({0})s)""".format(dimension.fieldname)
|
conditions += common_condition + "and ifnull(`tabSales Invoice Item`.{0}, '') in (%({0})s))".format(dimension.fieldname)
|
||||||
|
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
@ -127,6 +127,8 @@ def get_rootwise_opening_balances(filters, report_type):
|
|||||||
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
||||||
filters.get(dimension.fieldname))
|
filters.get(dimension.fieldname))
|
||||||
additional_conditions += "and {0} in %({0})s".format(dimension.fieldname)
|
additional_conditions += "and {0} in %({0})s".format(dimension.fieldname)
|
||||||
|
else:
|
||||||
|
additional_conditions += "and {0} in (%({0})s)".format(dimension.fieldname)
|
||||||
|
|
||||||
query_filters.update({
|
query_filters.update({
|
||||||
dimension.fieldname: filters.get(dimension.fieldname)
|
dimension.fieldname: filters.get(dimension.fieldname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user