Skip to content

Commit 9ec3031

Browse files
ili-adMatt Howardruthra-kumar
authored
fix(postgres): validate against period closing using MAX(period_end_date) (#51554)
* fix(postgres): validate against period closing using MAX(period_end_date) * refactor: remove non-existent field --------- Co-authored-by: Matt Howard <github.severity519@passmail.net> Co-authored-by: ruthra kumar <ruthra@erpnext.com>
1 parent e511503 commit 9ec3031

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

erpnext/accounts/general_ledger.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,12 +804,19 @@ def validate_against_pcv(is_opening, posting_date, company):
804804
title=_("Invalid Opening Entry"),
805805
)
806806

807-
last_pcv_date = frappe.db.get_value(
808-
"Period Closing Voucher", {"docstatus": 1, "company": company}, "max(period_end_date)"
809-
)
807+
# Local import so you don't have to touch file-level imports
808+
from frappe.query_builder.functions import Max
809+
810+
pcv = frappe.qb.DocType("Period Closing Voucher")
811+
812+
last_pcv_date = (
813+
frappe.qb.from_(pcv)
814+
.select(Max(pcv.period_end_date))
815+
.where((pcv.docstatus == 1) & (pcv.company == company))
816+
).run(pluck=True)[0]
810817

811818
if last_pcv_date and getdate(posting_date) <= getdate(last_pcv_date):
812-
message = _("Books have been closed till the period ending on {0}").format(formatdate(last_pcv_date))
819+
message = _("Books have been closed till the period ending on {0}.").format(formatdate(last_pcv_date))
813820
message += "</br >"
814821
message += _("You cannot create/amend any accounting entries till this date.")
815822
frappe.throw(message, title=_("Period Closed"))

0 commit comments

Comments
 (0)