From 69be22ba7cd97ef15274ecec3026f53d8baf72de Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sat, 14 May 2022 17:19:34 +0530 Subject: [PATCH] fix: select multiple values for accounting dimenssion --- .../accounting_dimension.py | 18 ++++++++++-------- .../accounts/report/financial_statements.py | 2 +- .../report/general_ledger/general_ledger.py | 2 +- .../purchase_register/purchase_register.py | 2 +- .../report/sales_register/sales_register.py | 2 +- .../report/trial_balance/trial_balance.py | 4 ++-- erpnext/public/js/utils.js | 6 ++++-- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 3f1998a3b3..ce1ed336d0 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -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 diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 56d68e1fa9..36825771f8 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -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 "" diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index 865cf14622..e4b561e5f6 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -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 "" diff --git a/erpnext/accounts/report/purchase_register/purchase_register.py b/erpnext/accounts/report/purchase_register/purchase_register.py index a73c72c6d8..e8a1e795d9 100644 --- a/erpnext/accounts/report/purchase_register/purchase_register.py +++ b/erpnext/accounts/report/purchase_register/purchase_register.py @@ -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 diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py index fc48dd2816..34b3f03206 100644 --- a/erpnext/accounts/report/sales_register/sales_register.py +++ b/erpnext/accounts/report/sales_register/sales_register.py @@ -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 diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py index dd0ac75654..e5a4ed2f34 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.py +++ b/erpnext/accounts/report/trial_balance/trial_balance.py @@ -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)}) diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index eded16529c..e8db097653 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -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); + }, }); } });