From b7f283b2f039b97997d938f9159ae045de44aba1 Mon Sep 17 00:00:00 2001 From: Gursheen Kaur Anand <40693548+GursheenK@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:55:37 +0530 Subject: [PATCH] feat: skip disabled accounts in COA (#38551) * feat: skip disabled accounts in coa * fix: add parameter to other tree doctype utils --- erpnext/accounts/utils.py | 6 +++++- erpnext/setup/doctype/department/department.py | 7 ++++++- erpnext/stock/doctype/warehouse/warehouse.py | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index adec0ab4e0..f9208f051e 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1116,12 +1116,16 @@ def get_companies(): @frappe.whitelist() -def get_children(doctype, parent, company, is_root=False): +def get_children(doctype, parent, company, is_root=False, include_disabled=False): + if isinstance(include_disabled, str): + include_disabled = frappe.json.loads(include_disabled) from erpnext.accounts.report.financial_statements import sort_accounts parent_fieldname = "parent_" + doctype.lower().replace(" ", "_") fields = ["name as value", "is_group as expandable"] filters = [["docstatus", "<", 2]] + if frappe.db.has_column(doctype, "disabled") and not include_disabled: + filters.append(["disabled", "=", False]) filters.append(['ifnull(`{0}`,"")'.format(parent_fieldname), "=", "" if is_root else parent]) diff --git a/erpnext/setup/doctype/department/department.py b/erpnext/setup/doctype/department/department.py index 16f6fbfba4..b36f032d4c 100644 --- a/erpnext/setup/doctype/department/department.py +++ b/erpnext/setup/doctype/department/department.py @@ -69,7 +69,9 @@ def get_abbreviated_name(name, company): @frappe.whitelist() -def get_children(doctype, parent=None, company=None, is_root=False): +def get_children(doctype, parent=None, company=None, is_root=False, include_disabled=False): + if isinstance(include_disabled, str): + include_disabled = frappe.json.loads(include_disabled) fields = ["name as value", "is_group as expandable"] filters = {} @@ -81,6 +83,9 @@ def get_children(doctype, parent=None, company=None, is_root=False): else: filters["parent_department"] = parent + if frappe.db.has_column(doctype, "disabled") and not include_disabled: + filters["disabled"] = False + return frappe.get_all("Department", fields=fields, filters=filters, order_by="name") diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index ef9b12eca2..07b354a4df 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -183,15 +183,20 @@ class Warehouse(NestedSet): @frappe.whitelist() -def get_children(doctype, parent=None, company=None, is_root=False): +def get_children(doctype, parent=None, company=None, is_root=False, include_disabled=False): if is_root: parent = "" + if isinstance(include_disabled, str): + include_disabled = frappe.json.loads(include_disabled) + fields = ["name as value", "is_group as expandable"] filters = [ ["ifnull(`parent_warehouse`, '')", "=", parent], ["company", "in", (company, None, "")], ] + if frappe.db.has_column(doctype, "disabled") and not include_disabled: + filters.append(["disabled", "=", False]) return frappe.get_list(doctype, fields=fields, filters=filters, order_by="name")