Skip to content

Commit

Permalink
Merge pull request #39674 from ruthra-kumar/add_account_type_warning
Browse files Browse the repository at this point in the history
refactor: use pop up to inform of possible data issue
  • Loading branch information
ruthra-kumar authored Feb 1, 2024
2 parents e9fe10c + 78483e2 commit 12affa7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions erpnext/accounts/doctype/account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 12affa7

Please sign in to comment.