From fa2b6c4490015a4c36e354f5702aed0e5974b228 Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Tue, 14 May 2024 17:56:06 +0530 Subject: [PATCH 1/2] fix: Asset cancelation issue --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index e32dcf1013d..594b5c10ca7 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -453,11 +453,12 @@ class JournalEntry(AccountsController): def unlink_asset_reference(self): for d in self.get("accounts"): + root_type = frappe.get_value("Account", d.account, "root_type") if ( self.voucher_type == "Depreciation Entry" and d.reference_type == "Asset" and d.reference_name - and d.account_type == "Depreciation" + and root_type == "Expense" and d.debit ): asset = frappe.get_doc("Asset", d.reference_name) From e843683ad1d90ef046690c66e582237473e1b108 Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Tue, 14 May 2024 20:03:58 +0530 Subject: [PATCH 2/2] style: code optimization --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 594b5c10ca7..84d05465bfc 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -453,12 +453,11 @@ class JournalEntry(AccountsController): def unlink_asset_reference(self): for d in self.get("accounts"): - root_type = frappe.get_value("Account", d.account, "root_type") if ( self.voucher_type == "Depreciation Entry" and d.reference_type == "Asset" and d.reference_name - and root_type == "Expense" + and frappe.get_cached_value("Account", d.account, "root_type") == "Expense" and d.debit ): asset = frappe.get_doc("Asset", d.reference_name)