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) <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user