From f8aa4c730c6b3eb4b02108251b8dab836aaefbef Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Thu, 18 Jun 2026 15:42:28 +0530 Subject: [PATCH] fix(journal entry): validate opening entry against pcv on save --- .../doctype/journal_entry/journal_entry.py | 4 ++++ erpnext/accounts/general_ledger.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 089da1fdb2c..4934a0788c1 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -19,6 +19,7 @@ from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger validate_docs_for_voucher_types, ) from erpnext.accounts.doctype.tax_withholding_entry.tax_withholding_entry import JournalTaxWithholding +from erpnext.accounts.general_ledger import validate_opening_entry_against_pcv from erpnext.accounts.party import get_party_account from erpnext.accounts.utils import ( cancel_exchange_gain_loss_journal, @@ -131,6 +132,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/general_ledger.py b/erpnext/accounts/general_ledger.py index 341488381a0..7030adbc88c 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -821,13 +821,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"}] )