From f4b827cb3dbb0e43baf19603195f6a4bc685d935 Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Fri, 19 Jun 2026 16:51:54 +0530 Subject: [PATCH] fix: honor account freezing date when cancelling vouchers --- .../doctype/purchase_invoice/test_purchase_invoice.py | 8 ++++++++ erpnext/accounts/general_ledger.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 509120acce3..fe73a7e4712 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -3008,6 +3008,14 @@ class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin): party_link.delete() + def test_purchase_invoice_cancellation_post_account_freezing_date(self): + pi = make_purchase_invoice() + frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", add_days(getdate(), 1)) + try: + self.assertRaises(frappe.ValidationError, pi.cancel) + finally: + frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", None) + def set_advance_flag(company, flag, default_account): frappe.db.set_value( diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 7030adbc88c..1619f93d456 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -716,7 +716,7 @@ def make_reverse_gl_entries( partial_cancel=partial_cancel, ) validate_accounting_period(gl_entries) - check_freezing_date(gl_entries[0]["posting_date"], adv_adj) + check_freezing_date(gl_entries[0]["posting_date"], gl_entries[0]["company"], adv_adj) is_opening = any(d.get("is_opening") == "Yes" for d in gl_entries)