From d406775d1ab9b5b5c3a73da4aa00e656cc239047 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Tue, 23 Nov 2021 20:21:24 +0530 Subject: [PATCH] fix: Check root_type of Depreciation Expense Account --- erpnext/assets/doctype/asset/depreciation.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index 0c96b519ed..874fb630f8 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -135,27 +135,19 @@ def get_depreciation_accounts(asset): return fixed_asset_account, accumulated_depreciation_account, depreciation_expense_account def get_credit_and_debit_accounts(accumulated_depreciation_account, depreciation_expense_account): - if is_income_or_expense_account(depreciation_expense_account) == "Expense": + root_type = frappe.get_value("Account", depreciation_expense_account, "root_type") + + if root_type == "Expense": credit_account = accumulated_depreciation_account debit_account = depreciation_expense_account - else: + elif root_type == "Income": credit_account = depreciation_expense_account debit_account = accumulated_depreciation_account + else: + frappe.throw(_("Depreciation Expense Account should be an Income or Expense Account.")) return credit_account, debit_account -def is_income_or_expense_account(account): - from frappe.utils.nestedset import get_ancestors_of - - ancestors = [ancestor.split(' - ')[0] for ancestor in get_ancestors_of("Account", account)] - if ancestors: - if "Expenses" in ancestors: - return "Expense" - elif "Income" in ancestors: - return "Income" - - frappe.throw(_("Depreciation Expense Account should be an Income or Expense Account.")) - @frappe.whitelist() def scrap_asset(asset_name): asset = frappe.get_doc("Asset", asset_name)