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, + )