Files
Odoo-Modules/fusion_clock/migrations/19.0.5.0.0/post-migrate.py
gsinghpal 1630a2025f 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>
2026-06-04 21:28:34 -04:00

41 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
#
# One-time port of Odoo Enterprise Planning data into the native Fusion Clock
# models, so a deployment that previously used the `planning` bridge keeps all
# its roles, employee role assignments and shifts after `planning` /
# `fusion_planning` are removed.
#
# Guarded: a no-op on Community / fresh installs where planning data is absent.
# Idempotent: a marker param stops it re-running.
import logging
from odoo import api, SUPERUSER_ID
_logger = logging.getLogger(__name__)
def migrate(cr, version):
"""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
# are allowed. Odoo drops removed declarative constraints on upgrade, but be
# explicit so the upgrade can never leave the old constraint behind.
cr.execute(
"ALTER TABLE fusion_clock_schedule "
"DROP CONSTRAINT IF EXISTS fusion_clock_schedule_employee_date_unique")
counts = env['fusion.clock.schedule'].sudo()._fclk_port_planning_data()
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)