Skip to content

Commit

Permalink
fix: select multiple values for accounting dimenssion
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed May 14, 2022
1 parent ead08aa commit 69be22b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,19 @@ def get_checks_for_pl_and_bs_accounts():
return dimensions


def get_dimension_with_children(doctype, dimension):
def get_dimension_with_children(doctype, dimensions):

if isinstance(dimension, list):
dimension = dimension[0]
if isinstance(dimensions, str):
dimensions = [dimensions]

all_dimensions = []
lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
children = frappe.get_all(
doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, order_by="lft"
)
all_dimensions += [c.name for c in children]

for dimension in dimensions:
lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
children = frappe.get_all(
doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, order_by="lft"
)
all_dimensions += [c.name for c in children]

return all_dimensions

Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/financial_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def get_additional_conditions(from_date, ignore_closing_entries, filters):
)
additional_conditions.append("{0} in %({0})s".format(dimension.fieldname))
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 ""

Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def get_conditions(filters):
)
conditions.append("{0} in %({0})s".format(dimension.fieldname))
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 ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def get_conditions(filters):
else:
conditions += (
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
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/sales_register/sales_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def get_conditions(filters):
else:
conditions += (
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
Expand Down
4 changes: 2 additions & 2 deletions erpnext/accounts/report/trial_balance/trial_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ def get_rootwise_opening_balances(filters, report_type):
filters[dimension.fieldname] = get_dimension_with_children(
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:
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)})

Expand Down
6 changes: 4 additions & 2 deletions erpnext/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ $.extend(erpnext.utils, {
filters.splice(index, 0, {
"fieldname": dimension["fieldname"],
"label": __(dimension["label"]),
"fieldtype": "Link",
"options": dimension["document_type"]
"fieldtype": "MultiSelectList",
get_data: function(txt) {
return frappe.db.get_link_options(dimension["document_type"], txt);
},
});
}
});
Expand Down

0 comments on commit 69be22b

Please sign in to comment.