fix: Check all ancestors and not just the root node
diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py
index 6591654..0c96b51 100644
--- a/erpnext/assets/doctype/asset/depreciation.py
+++ b/erpnext/assets/doctype/asset/depreciation.py
@@ -147,13 +147,11 @@
def is_income_or_expense_account(account):
from frappe.utils.nestedset import get_ancestors_of
- ancestors = get_ancestors_of("Account", account)
+ ancestors = [ancestor.split(' - ')[0] for ancestor in get_ancestors_of("Account", account)]
if ancestors:
- root_account = ancestors[-1].split(' - ')[0]
-
- if root_account == "Expenses":
+ if "Expenses" in ancestors:
return "Expense"
- elif root_account == "Income":
+ elif "Income" in ancestors:
return "Income"
frappe.throw(_("Depreciation Expense Account should be an Income or Expense Account."))