Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules180-190.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| contacts | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| crm | | |
| crm |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| crm_iap_enrich | |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
17 changes: 17 additions & 0 deletions openupgrade_scripts/scripts/crm/19.0.1.9/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
"""Populate crm.stage.team_ids m2m from legacy team_id (m2o -> m2m promotion)."""
legacy = openupgrade.get_legacy_name("team_id")
openupgrade.logged_query(
env.cr,
f"""
INSERT INTO crm_stage_crm_team_rel (crm_stage_id, crm_team_id)
SELECT id, {legacy}
FROM crm_stage
WHERE {legacy} IS NOT NULL
ON CONFLICT DO NOTHING
""",
)
10 changes: 10 additions & 0 deletions openupgrade_scripts/scripts/crm/19.0.1.9/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from openupgradelib import openupgrade

_renamed_columns = {
"crm_stage": [("team_id", None)],
}


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_columns(env.cr, _renamed_columns)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from odoo.tests import TransactionCase

from odoo.addons.openupgrade_framework import openupgrade_test


@openupgrade_test
class TestCrmMigration(TransactionCase):
def test_stage_team_m2m_populated(self):
"""The m2o→m2m promotion on crm.stage.team_id must preserve
relationships in the new team_ids m2m field.
"""
self.assertTrue(
self.env["crm.stage"].search([("team_ids", "!=", False)], limit=1),
"Migration should have populated crm.stage.team_ids from the "
"legacy team_id column.",
)

def test_legacy_column_remains(self):
"""Pre-migration renames the legacy FK column; it should still
be on disk so a later database_cleanup pass can drop it.
"""
self.env.cr.execute(
"""
SELECT column_name FROM information_schema.columns
WHERE table_name = 'crm_stage'
AND column_name = 'openupgrade_legacy_19_0_team_id'
"""
)
self.assertEqual(len(self.env.cr.fetchall()), 1)
30 changes: 30 additions & 0 deletions openupgrade_scripts/scripts/crm/19.0.1.9/upgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---Models in module 'crm'---
---Fields in module 'crm'---
crm / crm.lead / commercial_partner_id (many2one): NEW relation: res.partner, hasdefault: compute, stored: False
crm / crm.lead / mobile (char) : DEL
crm / crm.lead / title (many2one) : DEL relation: res.partner.title
crm / crm.lead / won_status (selection) : NEW selection_keys: ['lost', 'pending', 'won'], isfunction: function, stored
crm / crm.lead.scoring.frequency.field / color (integer) : NEW hasdefault: default
crm / crm.stage / color (integer) : NEW
crm / crm.stage / rotting_threshold_days (integer): NEW hasdefault: default
crm / crm.stage / team_id (many2one) : DEL relation: crm.team
crm / crm.stage / team_ids (many2many) : NEW relation: crm.team
crm / crm.team.member / assignment_domain_preferred (char): NEW
crm / res.users / target_sales_done (integer) : DEL
crm / res.users / target_sales_won (integer) : DEL

# DONE: crm.stage.team_id (m2o) -> team_ids (m2m) promotion handled by
# pre-migration rename_columns (preserve as legacy) + post-migration
# INSERT into crm_stage_crm_team_rel. All NEW fields are additive
# (default / compute / function-stored). DEL fields (crm.lead.mobile,
# crm.lead.title, res.users.target_sales_done/won) are left for
# database_cleanup per pedrobaeza policy.

---XML records in module 'crm'---
NEW ir.actions.act_window: crm.mail_followers_edit_action_from_lead
NEW ir.model.constraint: crm.constraint_crm_lead_create_date_team_id_idx
NEW ir.model.constraint: crm.constraint_crm_lead_default_order_idx
NEW ir.model.constraint: crm.constraint_crm_lead_user_id_team_id_type_index
DEL ir.ui.view: crm.crm_lead_partner_kanban_view

# NOTHING TO DO
7 changes: 7 additions & 0 deletions openupgrade_scripts/scripts/crm/tests/data_crm_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
env = locals().get("env")
team = env.ref("sales_team.team_sales_department", raise_if_not_found=False)
if team:
stage = env["crm.stage"].search([("team_id", "=", False)], limit=1)
if stage:
stage.team_id = team
env.cr.commit()
Loading