From 592ec1c5a5bf47a8c8f1a7b80f3ab0de2cbb42da Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Tue, 18 Nov 2025 14:51:46 +0530 Subject: [PATCH 1/3] fix: validate account type of depreciation account --- .../accounts/doctype/journal_entry/journal_entry.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 4fec8f2dd01..41206275420 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -326,7 +326,15 @@ class JournalEntry(AccountsController): def validate_depr_account_and_depr_entry_voucher_type(self): for d in self.get("accounts"): - if d.account_type == "Depreciation": + if ( + d.reference_type == "Asset" + and d.reference_name + and (d.account_type == "Depreciation" or self.voucher_type == "Depreciation Entry") + and d.debit + ): + if d.account_type != "Depreciation": + frappe.throw(_("Account {0} should be of type Depreciation").format(d.account)) + if self.voucher_type != "Depreciation Entry": frappe.throw( _("Journal Entry type should be set as Depreciation Entry for asset depreciation") From ca37f0371b67e0bad27c5bf908abde63ed51490a Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Tue, 18 Nov 2025 15:26:02 +0530 Subject: [PATCH 2/3] fix: validate root type as well --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 41206275420..aeb8c9970a3 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -326,10 +326,15 @@ class JournalEntry(AccountsController): def validate_depr_account_and_depr_entry_voucher_type(self): for d in self.get("accounts"): + root_type = frappe.get_cached_value("Account", d.account, "root_type") if ( d.reference_type == "Asset" and d.reference_name - and (d.account_type == "Depreciation" or self.voucher_type == "Depreciation Entry") + and ( + d.account_type == "Depreciation" + or self.voucher_type == "Depreciation Entry" + or root_type == "Expense" + ) and d.debit ): if d.account_type != "Depreciation": @@ -340,7 +345,7 @@ class JournalEntry(AccountsController): _("Journal Entry type should be set as Depreciation Entry for asset depreciation") ) - if frappe.get_cached_value("Account", d.account, "root_type") != "Expense": + if root_type != "Expense": frappe.throw(_("Account {0} should be of type Expense").format(d.account)) def validate_stock_accounts(self): From 68d6fc142bfafce21df1a2da5235d45e87656e24 Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Tue, 18 Nov 2025 16:26:35 +0530 Subject: [PATCH 3/3] fix: check root type instead of account type --- .../doctype/journal_entry/journal_entry.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index aeb8c9970a3..e4aaf4e7a5a 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -326,26 +326,13 @@ class JournalEntry(AccountsController): def validate_depr_account_and_depr_entry_voucher_type(self): for d in self.get("accounts"): - root_type = frappe.get_cached_value("Account", d.account, "root_type") - if ( - d.reference_type == "Asset" - and d.reference_name - and ( - d.account_type == "Depreciation" - or self.voucher_type == "Depreciation Entry" - or root_type == "Expense" - ) - and d.debit - ): - if d.account_type != "Depreciation": - frappe.throw(_("Account {0} should be of type Depreciation").format(d.account)) - + if d.account_type == "Depreciation": if self.voucher_type != "Depreciation Entry": frappe.throw( _("Journal Entry type should be set as Depreciation Entry for asset depreciation") ) - if root_type != "Expense": + if frappe.get_cached_value("Account", d.account, "root_type") != "Expense": frappe.throw(_("Account {0} should be of type Expense").format(d.account)) def validate_stock_accounts(self): @@ -466,7 +453,7 @@ class JournalEntry(AccountsController): if ( d.reference_type == "Asset" and d.reference_name - and d.account_type == "Depreciation" + and frappe.get_cached_value("Account", d.account, "root_type") == "Expense" and d.debit ): asset = frappe.get_cached_doc("Asset", d.reference_name)