90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1
|
|
#
|
|
# Phase 1 (Sub 11) — relocate ir.model.data XML IDs from
|
|
# fusion_plating_bridge_mrp to fusion_plating_jobs for the four
|
|
# models that moved: fp.work.role, fp.operator.proficiency,
|
|
# fp.qc.checklist.template (+line), fp.job.consumption.
|
|
#
|
|
# Pre-migration so Odoo's normal load pass sees the records under the
|
|
# new module owner, not as orphans pending deletion.
|
|
#
|
|
# Idempotent — `ON CONFLICT DO NOTHING` skips rows already migrated.
|
|
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
def migrate(cr, version):
|
|
if not version:
|
|
return # Fresh install — nothing to migrate
|
|
|
|
moves = [
|
|
# (xmlid pattern, list of model identifiers to move)
|
|
('model_fp_job_consumption',),
|
|
# ACL records (csv:id values get prefixed with the owning module)
|
|
('access_fp_job_consumption_%',),
|
|
]
|
|
for (pat,) in moves:
|
|
cr.execute(
|
|
"""
|
|
UPDATE ir_model_data
|
|
SET module = 'fusion_plating_jobs'
|
|
WHERE module = 'fusion_plating_bridge_mrp'
|
|
AND name LIKE %s
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM ir_model_data d2
|
|
WHERE d2.module = 'fusion_plating_jobs'
|
|
AND d2.name = ir_model_data.name
|
|
)
|
|
""",
|
|
(pat,),
|
|
)
|
|
if cr.rowcount:
|
|
_logger.info(
|
|
"Sub 11: re-keyed %d ir.model.data rows matching %s -> fusion_plating_jobs",
|
|
cr.rowcount, pat,
|
|
)
|
|
|
|
# Views, actions, menus that the old module created
|
|
view_patterns = [
|
|
'view_fp_job_consumption_%',
|
|
'action_fp_job_consumption%',
|
|
'menu_fp_job_consumption%',
|
|
]
|
|
for pat in view_patterns:
|
|
cr.execute(
|
|
"""
|
|
UPDATE ir_model_data
|
|
SET module = 'fusion_plating_jobs'
|
|
WHERE module = 'fusion_plating_bridge_mrp'
|
|
AND name LIKE %s
|
|
AND NOT EXISTS (
|
|
SELECT 1 FROM ir_model_data d2
|
|
WHERE d2.module = 'fusion_plating_jobs'
|
|
AND d2.name = ir_model_data.name
|
|
)
|
|
""",
|
|
(pat,),
|
|
)
|
|
if cr.rowcount:
|
|
_logger.info(
|
|
"Sub 11: re-keyed %d row(s) for %s -> fusion_plating_jobs",
|
|
cr.rowcount, pat,
|
|
)
|
|
|
|
# Phase 1 swap: fp.job.consumption columns. Drop the legacy
|
|
# MRP-pointing columns (production_id, workorder_id) from the
|
|
# already-existing table — there are zero rows referencing MRP, and
|
|
# the new model declares job_id / step_id instead.
|
|
cr.execute(
|
|
"""
|
|
ALTER TABLE fp_job_consumption
|
|
DROP COLUMN IF EXISTS production_id,
|
|
DROP COLUMN IF EXISTS workorder_id
|
|
"""
|
|
)
|
|
_logger.info("Sub 11: dropped MRP columns on fp_job_consumption")
|