fix: Validation for cancelation
diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
index 8f1bf51..9d636ad 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
@@ -31,6 +31,7 @@
self.make_gl_entries(get_opening_entries=get_opening_entries)
def on_cancel(self):
+ self.validate_future_closing_vouchers()
self.db_set("gle_processing_status", "In Progress")
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
gle_count = frappe.db.count(
@@ -52,6 +53,17 @@
self.delete_closing_entries()
+ def validate_future_closing_vouchers(self):
+ if frappe.db.exists(
+ "Period Closing Voucher",
+ {"posting_date": (">", self.posting_date), "docstatus": 1, "company": self.company},
+ ):
+ frappe.throw(
+ _(
+ "You can not cancel this Period Closing Voucher, please cancel the future Period Closing Vouchers first"
+ )
+ )
+
def delete_closing_entries(self):
closing_balance = frappe.qb.DocType("Account Closing Balance")
frappe.qb.from_(closing_balance).delete().where(