fix: select multiple values for accounting dimenssion

This commit is contained in:
Rohit Waghchaure 2022-05-14 17:19:34 +05:30
parent ead08aa192
commit 69be22ba7c
7 changed files with 20 additions and 16 deletions

View File

@ -234,17 +234,19 @@ def get_checks_for_pl_and_bs_accounts():
return dimensions return dimensions
def get_dimension_with_children(doctype, dimension): def get_dimension_with_children(doctype, dimensions):
if isinstance(dimension, list): if isinstance(dimensions, str):
dimension = dimension[0] dimensions = [dimensions]
all_dimensions = [] all_dimensions = []
lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
children = frappe.get_all( for dimension in dimensions:
doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, order_by="lft" lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
) children = frappe.get_all(
all_dimensions += [c.name for c in children] doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, order_by="lft"
)
all_dimensions += [c.name for c in children]
return all_dimensions return all_dimensions

View File

@ -507,7 +507,7 @@ def get_additional_conditions(from_date, ignore_closing_entries, filters):
) )
additional_conditions.append("{0} in %({0})s".format(dimension.fieldname)) additional_conditions.append("{0} in %({0})s".format(dimension.fieldname))
else: else:
additional_conditions.append("{0} in (%({0})s)".format(dimension.fieldname)) 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 ""

View File

@ -275,7 +275,7 @@ def get_conditions(filters):
) )
conditions.append("{0} in %({0})s".format(dimension.fieldname)) conditions.append("{0} in %({0})s".format(dimension.fieldname))
else: else:
conditions.append("{0} in (%({0})s)".format(dimension.fieldname)) 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 ""

View File

@ -237,7 +237,7 @@ def get_conditions(filters):
else: else:
conditions += ( conditions += (
common_condition common_condition
+ "and ifnull(`tabPurchase Invoice Item`.{0}, '') in (%({0})s))".format(dimension.fieldname) + "and ifnull(`tabPurchase Invoice Item`.{0}, '') in %({0})s)".format(dimension.fieldname)
) )
return conditions return conditions

View File

@ -405,7 +405,7 @@ def get_conditions(filters):
else: else:
conditions += ( conditions += (
common_condition common_condition
+ "and ifnull(`tabSales Invoice Item`.{0}, '') in (%({0})s))".format(dimension.fieldname) + "and ifnull(`tabSales Invoice Item`.{0}, '') in %({0})s)".format(dimension.fieldname)
) )
return conditions return conditions

View File

@ -188,9 +188,9 @@ def get_rootwise_opening_balances(filters, report_type):
filters[dimension.fieldname] = get_dimension_with_children( filters[dimension.fieldname] = get_dimension_with_children(
dimension.document_type, filters.get(dimension.fieldname) dimension.document_type, 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: else:
additional_conditions += "and {0} in (%({0})s)".format(dimension.fieldname) additional_conditions += " and {0} in %({0})s".format(dimension.fieldname)
query_filters.update({dimension.fieldname: filters.get(dimension.fieldname)}) query_filters.update({dimension.fieldname: filters.get(dimension.fieldname)})

View File

@ -213,8 +213,10 @@ $.extend(erpnext.utils, {
filters.splice(index, 0, { filters.splice(index, 0, {
"fieldname": dimension["fieldname"], "fieldname": dimension["fieldname"],
"label": __(dimension["label"]), "label": __(dimension["label"]),
"fieldtype": "Link", "fieldtype": "MultiSelectList",
"options": dimension["document_type"] get_data: function(txt) {
return frappe.db.get_link_options(dimension["document_type"], txt);
},
}); });
} }
}); });