Skip to content

[19.0][MIG] crm: m2o->m2m promotion on crm.stage.team_id#5643

Open
dnplkndll wants to merge 2 commits into
OCA:19.0from
ledoent:19.0-mig-crm-stage-teams
Open

[19.0][MIG] crm: m2o->m2m promotion on crm.stage.team_id#5643
dnplkndll wants to merge 2 commits into
OCA:19.0from
ledoent:19.0-mig-crm-stage-teams

Conversation

@dnplkndll
Copy link
Copy Markdown

Summary

19.0 promotes `crm.stage.team_id` (many2one to `crm.team`) to `team_ids` (many2many). Without an explicit migration, the per-stage team assignment is lost (rendered as DEL old + NEW empty by OpenUpgrade's analysis).

Migration

  • pre-migration.py — `openupgrade.get_legacy_name` + `rename_columns` to preserve the legacy FK column past ORM init.
  • post-migration.py — INSERT into the new m2m relation table `crm_stage_crm_team_rel` from the legacy column. Each previously-assigned team_id becomes a single (stage_id, team_id) row.
  • Legacy column preserved for `database_cleanup` to pick up.

Test coverage

`openupgrade_scripts/scripts/crm/19.0.1.9/tests/test_crm_migration.py`:

  1. asserts at least one stage has `team_ids` populated post-migration
  2. asserts the legacy column still exists for `database_cleanup`

`openupgrade_scripts/scripts/crm/tests/data_crm_migration.py` — 18.0 demo seed: sets `team_id` on at least one stage so the migration UPDATE has rows.

What this PR does NOT touch

Per pedrobaeza policy, these 19.0 changes in `crm` are intentionally left alone:

  • DEL `crm.lead.mobile`, `crm.lead.title` — denormalized lookup fields, leave for database_cleanup
  • DEL `res.users.target_sales_done`, `target_sales_won` — replaced by computed-stored equivalents
  • NEW `crm.lead.commercial_partner_id` (compute, stored=False) — auto-populates
  • NEW `crm.lead.won_status` (function-stored) — auto-populates
  • NEW `crm.stage.color`, `rotting_threshold_days` — additive, ORM handles

Fork CI

Validated on fork's `Test OpenUpgrade migration` workflow (both base + enriched seeds passed): 2026-05-16T01:58Z.

docsource

`docsource/modules180-190.rst` updated — `crm` marked Done.

@OCA-git-bot OCA-git-bot added mod:openupgrade_scripts Module openupgrade_scripts series:19.0 labels May 18, 2026
dnplkndll added 2 commits May 18, 2026 21:16
19.0 promotes crm.stage.team_id (many2one to crm.team) to
team_ids (many2many to crm.team). Pre-migration renames the legacy
FK column via get_legacy_name so it survives ORM init; post-migration
INSERTs from the legacy column into crm_stage_crm_team_rel.

Test asserts at least one stage has team_ids populated, plus that
the legacy column remains for database_cleanup pickup. tests/data_crm_migration.py
seeds 18.0 demo stages with team_id so the migration has data to
exercise on the OCA seed.

Other 19.0 changes left alone per pedrobaeza policy:
- DEL crm.lead.mobile, crm.lead.title (denormalized — leave)
- DEL res.users.target_sales_done, target_sales_won (counters — leave)
- NEW crm.lead.commercial_partner_id (compute, stored: False)
- NEW crm.lead.won_status (function-stored, auto-populated)
- NEW crm.stage.color, rotting_threshold_days (additive)
Self-review fixes before OCA review:

- post-migration: add ON CONFLICT DO NOTHING to the m2m INSERT.
  Re-runs (idempotent retries; OpenUpgrade partial-failure recovery)
  hit the (crm_stage_id, crm_team_id) PK without it. Trim docstring.
- data seed: replace raw-SQL UPDATE-from-first-team-in-table with
  env.ref('sales_team.team_sales_department') + ORM assignment. The
  original UPDATE silently set all stages to NULL if crm_team was
  empty in the seed DB. Drops the 4-line preamble comment.
@dnplkndll dnplkndll force-pushed the 19.0-mig-crm-stage-teams branch from 72f6b98 to 66cc730 Compare May 19, 2026 01:16
@dnplkndll dnplkndll marked this pull request as ready for review May 19, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:openupgrade_scripts Module openupgrade_scripts series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants