From 30eb6c851265365c829e1d915d6058128e99e129 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 23 Mar 2023 19:05:25 +0530 Subject: [PATCH] fix: Validation for cancelation --- .../period_closing_voucher/period_closing_voucher.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 8f1bf51a2f..9d636adc57 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 @@ class PeriodClosingVoucher(AccountsController): 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 @@ class PeriodClosingVoucher(AccountsController): 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(