From e23a7883f3f1022c112d9d82d99d94cab0afa6a9 Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Thu, 18 Jun 2026 15:43:02 +0530 Subject: [PATCH] fix(journal entry): validate opening entry against pcv on save --- .../doctype/journal_entry/journal_entry.py | 4 ++++ erpnext/accounts/services/gl_validator.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 70e6164beb2..2e4197014a0 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -28,6 +28,7 @@ from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger ) from erpnext.accounts.doctype.tax_withholding_entry.tax_withholding_entry import JournalTaxWithholding from erpnext.accounts.party import get_party_account +from erpnext.accounts.services.gl_validator import validate_opening_entry_against_pcv from erpnext.accounts.utils import ( cancel_exchange_gain_loss_journal, get_account_currency, @@ -149,6 +150,9 @@ class JournalEntry(AccountsController): if not self.is_opening: self.is_opening = "No" + if self.is_opening == "Yes": + validate_opening_entry_against_pcv(self.company) + self.clearance_date = None self.validate_party() diff --git a/erpnext/accounts/services/gl_validator.py b/erpnext/accounts/services/gl_validator.py index e29b4d42103..fd597fb38a8 100644 --- a/erpnext/accounts/services/gl_validator.py +++ b/erpnext/accounts/services/gl_validator.py @@ -122,13 +122,24 @@ def check_freezing_date(posting_date, company, adv_adj=False): ) -def validate_against_pcv(is_opening, posting_date, company): - if is_opening and frappe.db.exists("Period Closing Voucher", {"docstatus": 1, "company": company}): +def validate_opening_entry_against_pcv(company): + if frappe.db.exists("Period Closing Voucher", {"docstatus": 1, "company": company}): frappe.throw( - _("Opening Entry can not be created after Period Closing Voucher is created."), + _( + "A Period Closing Voucher is already submitted and an Opening Entry can no longer be created. {0} to learn more." + ).format( + '' + + _("Read the docs") + + "" + ), title=_("Invalid Opening Entry"), ) + +def validate_against_pcv(is_opening, posting_date, company): + if is_opening: + validate_opening_entry_against_pcv(company) + last_pcv_date = frappe.db.get_value( "Period Closing Voucher", {"docstatus": 1, "company": company}, [{"MAX": "period_end_date"}] )