fix: Check all ancestors and not just the root node

This commit is contained in:
GangaManoj 2021-11-17 05:22:43 +05:30
parent 62fbbe8915
commit cb93cc972d

View File

@ -147,13 +147,11 @@ def get_credit_and_debit_accounts(accumulated_depreciation_account, depreciation
def is_income_or_expense_account(account): def is_income_or_expense_account(account):
from frappe.utils.nestedset import get_ancestors_of 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: if ancestors:
root_account = ancestors[-1].split(' - ')[0] if "Expenses" in ancestors:
if root_account == "Expenses":
return "Expense" return "Expense"
elif root_account == "Income": elif "Income" in ancestors:
return "Income" return "Income"
frappe.throw(_("Depreciation Expense Account should be an Income or Expense Account.")) frappe.throw(_("Depreciation Expense Account should be an Income or Expense Account."))