feat: Add validations against period closing voucher
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 41fdb6a..9fff6f4 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -300,6 +300,9 @@
if gl_map:
check_freezing_date(gl_map[0]["posting_date"], adv_adj)
+ is_opening = any(d.get("is_opening") == "Yes" for d in gl_map)
+ if gl_map[0]["voucher_type"] != "Period Closing Voucher":
+ validate_against_pcv(is_opening, gl_map[0]["posting_date"], gl_map[0]["company"])
for entry in gl_map:
make_entry(entry, adv_adj, update_outstanding, from_repost)
@@ -519,6 +522,9 @@
)
validate_accounting_period(gl_entries)
check_freezing_date(gl_entries[0]["posting_date"], adv_adj)
+
+ is_opening = any(d.get("is_opening") == "Yes" for d in gl_entries)
+ validate_against_pcv(is_opening, gl_entries[0]["posting_date"], gl_entries[0]["company"])
set_as_cancel(gl_entries[0]["voucher_type"], gl_entries[0]["voucher_no"])
for entry in gl_entries:
@@ -566,6 +572,28 @@
)
+def validate_against_pcv(is_opening, posting_date, company):
+ if is_opening and frappe.db.exists(
+ "Period Closing Voucher", {"docstatus": 1, "company": company}
+ ):
+ frappe.throw(
+ _("Opening Entry can not be created after Period Closing Voucher is created."),
+ title=_("Invalid Opening Entry"),
+ )
+
+ last_pcv_date = frappe.db.get_value(
+ "Period Closing Voucher", {"docstatus": 1, "company": company}, "max(posting_date)"
+ )
+
+ if last_pcv_date and getdate(posting_date) <= getdate(last_pcv_date):
+ message = _("Books have been closed till the period ending on {0}").format(
+ formatdate(last_pcv_date)
+ )
+ message += "</br >"
+ message += _("You cannot create any new accounting entries till this date.")
+ frappe.throw(message, title=_("Period Closed"))
+
+
def set_as_cancel(voucher_type, voucher_no):
"""
Set is_cancelled=1 in all original gl entries for the voucher