Skip to content

Commit

Permalink
fix: validate disabled accounts before posting ledger entries
Browse files Browse the repository at this point in the history
(cherry picked from commit 95b059a)
  • Loading branch information
nextchamp-saqib authored and mergify[bot] committed May 12, 2022
1 parent 047c879 commit 515e49b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def make_gl_entries(
if gl_map:
if not cancel:
validate_accounting_period(gl_map)
validate_disabled_accounts(gl_map)
gl_map = process_gl_map(gl_map, merge_entries)
if gl_map and len(gl_map) > 1:
save_entries(gl_map, adv_adj, update_outstanding, from_repost)
Expand All @@ -43,6 +44,26 @@ def make_gl_entries(
make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)


def validate_disabled_accounts(gl_map):
accounts = [d.account for d in gl_map if d.account]

Account = frappe.qb.DocType("Account")

disabled_accounts = (
frappe.qb.from_(Account)
.where(Account.name.isin(accounts) & Account.disabled == 1)
.select(Account.name, Account.disabled)
).run(as_dict=True)

if disabled_accounts:
account_list = "<br>"
account_list += ", ".join([frappe.bold(d.name) for d in disabled_accounts])
frappe.throw(
_("Cannot create accounting entries against disabled accounts: {0}").format(account_list),
title=_("Disabled Account Selected"),
)


def validate_accounting_period(gl_map):
accounting_periods = frappe.db.sql(
""" SELECT
Expand Down

0 comments on commit 515e49b

Please sign in to comment.