Cannot cancel period closing voucher

I’m wondering if others have been blocked from posting to a closed period. I used to be able to post adjustments to past periods, and simply create a new period closing entry. But now I am blocked from posting journal entries with this error:

Books have been closed till the period ending on 2022-12-31
You cannot create/amend any accounting entries till this date.

I tried to create a new period close voucher for the previously closed period, but I’m getting the following error:

Another Period Closing Entry PCE/014 has been made after 2022-12-31.

I’ve tried cancelling the submitted periods, but I get the same error. Is there something I’m doing wrong? Cancelling a period will make changes to the GL for the period, which is blocked by the voucher. Thus you can never cancel a PCV.

Looking at the period closing voucher code, it appears that you cannot save a period close voucher if there are submitted prior closes that posted on the same date. Shouldn’t it allow close vouchers that post on the same date?

The code in question looks like this:

existing_entry = (
frappe.qb.from_(pcv)
.select(pcv.name)
.where(
(pcv.posting_date >= self.posting_date)
& (pcv.fiscal_year == self.fiscal_year)
& (pcv.docstatus == 1)
& (pcv.company == self.company)
)
.run()
)

  if existing_entry and existing_entry[0][0]:
  	frappe.throw(
  		_("Another Period Closing Entry {0} has been made after {1}").format(
  			existing_entry[0][0], self.posting_date
  		)
  	)

One thing to note, is I have three period closing vouchers for 2022. I cannot cancel any of them. I suspect this is the problem and might be a bug that blocks pcv cancellation.

I think I solved the issue with the following code change to general_ledger.py. I don’t recommend anyone do this though.

def make_reverse_gl_entries(
gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding=“Yes”
):
“”"
Get original gl entries of the voucher
and make reverse gl entries by swapping debit and credit
“”"

if not gl_entries:
    gl_entry = frappe.qb.DocType("GL Entry")
    gl_entries = (
        frappe.qb.from_(gl_entry)
        .select("*")
        .where(gl_entry.voucher_type == voucher_type)
        .where(gl_entry.voucher_no == voucher_no)
        .where(gl_entry.is_cancelled == 0)
        .for_update()
    ).run(as_dict=1)

if gl_entries:
    create_payment_ledger_entry(
        gl_entries, cancel=1, adv_adj=adv_adj, update_outstanding=update_outstanding
    )
    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)
    if voucher_type != "Period Closing Voucher":
        validate_against_pcv(is_opening, gl_entries[0]["posting_date"], gl_entries[0]["company"])