changes
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1
|
||||
# Sub 9 — Process Variants per Part. Runs on upgrade to 19.0.15.0.0.
|
||||
#
|
||||
# For every part that had a default_process_id, mark its root node as
|
||||
# the default variant and seed a friendly label. Idempotent (NULL guards).
|
||||
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return # Fresh install — nothing to migrate
|
||||
|
||||
_logger.info("Sub 9: backfilling process variant flags")
|
||||
|
||||
# Step 1: Mark each part's existing default_process_id root as the
|
||||
# default variant. The flag is cleared on every other root so we
|
||||
# land in a consistent "exactly one default" state.
|
||||
cr.execute("""
|
||||
UPDATE fusion_plating_process_node
|
||||
SET is_default_variant = FALSE
|
||||
WHERE parent_id IS NULL
|
||||
AND node_type = 'recipe'
|
||||
AND part_catalog_id IS NOT NULL
|
||||
""")
|
||||
_logger.info("Sub 9: cleared is_default_variant on %d roots", cr.rowcount)
|
||||
|
||||
cr.execute("""
|
||||
UPDATE fusion_plating_process_node node
|
||||
SET is_default_variant = TRUE
|
||||
FROM fp_part_catalog part
|
||||
WHERE part.default_process_id = node.id
|
||||
AND node.parent_id IS NULL
|
||||
AND node.node_type = 'recipe'
|
||||
AND node.part_catalog_id = part.id
|
||||
""")
|
||||
_logger.info(
|
||||
"Sub 9: flagged is_default_variant on %d roots (one per part with default_process_id)",
|
||||
cr.rowcount,
|
||||
)
|
||||
|
||||
# Step 2: Seed variant_label='Default' on the now-flagged variants
|
||||
# so the picker shows something readable. Only fills NULL/empty.
|
||||
cr.execute("""
|
||||
UPDATE fusion_plating_process_node
|
||||
SET variant_label = 'Default'
|
||||
WHERE is_default_variant = TRUE
|
||||
AND (variant_label IS NULL OR variant_label = '')
|
||||
""")
|
||||
_logger.info("Sub 9: seeded variant_label='Default' on %d records", cr.rowcount)
|
||||
|
||||
_logger.info("Sub 9: migration complete")
|
||||
Reference in New Issue
Block a user