From 78483e2ee6fdef9e36b63408f6796f0a1e78dac1 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 1 Feb 2024 16:05:27 +0530 Subject: [PATCH] refactor: use pop up to inform of possible data issue and leave a comment in communcation trail as well --- erpnext/accounts/doctype/account/account.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index 651599dafd60..3f11798c2a48 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -118,6 +118,7 @@ def validate(self): self.validate_balance_must_be_debit_or_credit() self.validate_account_currency() self.validate_root_company_and_sync_account_to_children() + self.validate_receivable_payable_account_type() def validate_parent_child_account_type(self): if self.parent_account: @@ -188,6 +189,24 @@ def set_root_and_report_type(self): "Balance Sheet" if self.root_type in ("Asset", "Liability", "Equity") else "Profit and Loss" ) + def validate_receivable_payable_account_type(self): + doc_before_save = self.get_doc_before_save() + receivable_payable_types = ["Receivable", "Payable"] + if ( + doc_before_save + and doc_before_save.account_type in receivable_payable_types + and doc_before_save.account_type != self.account_type + ): + # check for ledger entries + if frappe.db.get_all("GL Entry", filters={"account": self.name, "is_cancelled": 0}, limit=1): + msg = _( + "There are ledger entries against this account. Changing {0} to non-{1} in live system will cause incorrect output in 'Accounts {2}' report" + ).format( + frappe.bold("Account Type"), doc_before_save.account_type, doc_before_save.account_type + ) + frappe.msgprint(msg) + self.add_comment("Comment", msg) + def validate_root_details(self): doc_before_save = self.get_doc_before_save()