From 96ebd398cc3e4cacc90541acbb6714e516ad4cf8 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 --- .../doctype/journal_entry/journal_entry.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 12db5753a1..5fa38ed2d8 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -157,6 +157,20 @@ class JournalEntry(AccountsController): if not self.title: self.title = self.get_title() + def validate_advance_accounts(self): + journal_accounts = set([x.account for x in self.accounts]) + advance_accounts = set() + advance_accounts.add( + frappe.get_cached_value("Company", self.company, "default_advance_received_account") + ) + advance_accounts.add(frappe.get_cached_value("Company", self.company, "default_advance_paid_account")) + if advance_accounts_used := journal_accounts & advance_accounts: + frappe.msgprint( + _( + "Making Journal Entries against advance accounts: {0} is not recommended. These Journals won't be available for Reconciliation." + ).format(frappe.bold(comma_and(advance_accounts_used))) + ) + def validate_for_repost(self): validate_docs_for_voucher_types(["Journal Entry"]) validate_docs_for_deferred_accounting([self.name], []) @@ -440,11 +454,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) -- GitLab From b33c62bcfecf08a05ecd622eddfe9ecdae5fed3d 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 5fa38ed2d8..436b2c3907 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -454,12 +454,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) -- GitLab