From 3a41370189f63d48145a14e5141531a5d568c913 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Tue, 12 May 2026 18:41:15 -0400 Subject: [PATCH] fix(nexa_coa_setup): tolerant fiscal-year lock hook The post_init_hook attempt to set fiscalyear_lock_date=2025-12-31 fails with RedirectWarning when unreconciled bank statement lines exist in the period. Catch RedirectWarning/UserError/ValidationError, log a clear instruction to set the lock manually after reconciliation, and let install continue. Co-Authored-By: Claude Opus 4.7 (1M context) --- nexa_coa_setup/hooks.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/nexa_coa_setup/hooks.py b/nexa_coa_setup/hooks.py index 28a12ed6..4c524c2e 100644 --- a/nexa_coa_setup/hooks.py +++ b/nexa_coa_setup/hooks.py @@ -39,12 +39,30 @@ def _rename_legacy_accounts(env): def _lock_fiscal_year_2025(env): - """Set fiscalyear_lock_date = 2025-12-31 on main company.""" + """Try to set fiscalyear_lock_date = 2025-12-31 on main company. + + If Odoo blocks the lock because unreconciled bank statement lines or other + open items exist in the period, log a clear warning and continue. The user + can set the lock manually via Accounting > Configuration > Settings > Lock + Dates once those items are cleaned up. + """ from datetime import date + from odoo.exceptions import RedirectWarning, UserError, ValidationError company = env.ref("base.main_company", raise_if_not_found=False) if not company: return target = date(2025, 12, 31) - if not company.fiscalyear_lock_date or company.fiscalyear_lock_date < target: + if company.fiscalyear_lock_date and company.fiscalyear_lock_date >= target: + _logger.info("nexa_coa_setup: fiscalyear_lock_date already at or after 2025-12-31") + return + try: company.fiscalyear_lock_date = target _logger.info("nexa_coa_setup: fiscalyear_lock_date set to 2025-12-31") + except (RedirectWarning, UserError, ValidationError) as exc: + _logger.warning( + "nexa_coa_setup: could not auto-lock fiscal year 2025-12-31. " + "Reason: %s. Set the lock manually via Accounting > Configuration > " + "Settings > Lock Dates after the unreconciled items in the period " + "are cleaned up.", + exc, + )