fix(fusion_clock): planning port defers when planning ORM not loaded during -u

fusion_clock doesn't depend on planning, so planning's models load AFTER it
during -u and the port saw no data. Now detect planning tables via SQL,
defer (no marker) when the ORM isn't loaded, and finish the port from the
deploy odoo-shell step (full registry). Marker now owned by the method.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-06-04 21:28:34 -04:00
parent 498963e83a
commit 1630a2025f
3 changed files with 43 additions and 17 deletions

View File

@@ -16,13 +16,13 @@ from odoo import api, SUPERUSER_ID
_logger = logging.getLogger(__name__)
_MARKER = 'fusion_clock.planning_migrated'
def migrate(cr, version):
"""Port Odoo Planning data into the native models, once. The heavy lifting
lives in fusion.clock.schedule._fclk_port_planning_data so it can be unit
tested on an Enterprise clone where planning is installed."""
"""Drop the legacy one-shift-per-day constraint and attempt the planning ->
native port. The port (fusion.clock.schedule._fclk_port_planning_data) is
marker-guarded and self-defers: because fusion_clock doesn't depend on
planning, planning's ORM may not be loaded here, in which case the deploy
shell step finishes the port. Lives in the model so it's unit-testable."""
env = api.Environment(cr, SUPERUSER_ID, {})
# Phase B drops the hard one-shift-per-day uniqueness so split/open shifts
@@ -32,10 +32,9 @@ def migrate(cr, version):
"ALTER TABLE fusion_clock_schedule "
"DROP CONSTRAINT IF EXISTS fusion_clock_schedule_employee_date_unique")
ICP = env['ir.config_parameter'].sudo()
if ICP.get_param(_MARKER):
_logger.info("Fusion Clock: planning data already migrated; skipping.")
return
counts = env['fusion.clock.schedule'].sudo()._fclk_port_planning_data()
ICP.set_param(_MARKER, '1')
_logger.info("Fusion Clock: planning -> native migration done: %s", counts)
if counts.get('deferred'):
_logger.info("Fusion Clock: planning models not loaded during migration; "
"data will be ported by the deploy shell step.")
else:
_logger.info("Fusion Clock: planning -> native migration: %s", counts)