Skip to content

Commit 73525be

Browse files
[OU-ADD] crm: Migration scripts
1 parent 4591593 commit 73525be

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

docsource/modules180-190.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Module coverage 18.0 -> 19.0
112112
+---------------------------------------------------+----------------------+-------------------------------------------------+
113113
| contacts |Nothing to do | |
114114
+---------------------------------------------------+----------------------+-------------------------------------------------+
115-
| crm | | |
115+
| crm |Done | |
116116
+---------------------------------------------------+----------------------+-------------------------------------------------+
117117
| crm_iap_enrich | |No DB layout changes. |
118118
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2026 Tecnativa - Eduardo Ezerouali
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from openupgradelib import openupgrade
4+
5+
6+
def _migrate_lead_mobile(env):
7+
# Case 1: phone is empty → fill it with the old mobile value
8+
openupgrade.logged_query(
9+
env.cr,
10+
"""
11+
UPDATE crm_lead
12+
SET phone = mobile
13+
WHERE (phone IS NULL OR phone = '')
14+
AND (mobile IS NOT NULL AND mobile != '')
15+
""",
16+
)
17+
18+
19+
def _won_stage_field(env):
20+
openupgrade.logged_query(
21+
env.cr,
22+
"""
23+
UPDATE crm_lead cl
24+
SET won_status = CASE
25+
WHEN cl.probability = 100
26+
AND EXISTS (
27+
SELECT 1 FROM crm_stage cs
28+
WHERE cs.id = cl.stage_id
29+
AND cs.is_won = TRUE
30+
)
31+
THEN 'won'
32+
WHEN cl.active = FALSE
33+
AND cl.probability = 0
34+
THEN 'lost'
35+
ELSE 'pending'
36+
END
37+
""",
38+
)
39+
40+
41+
@openupgrade.migrate()
42+
def migrate(env, version):
43+
openupgrade.load_data(env, "crm", "19.0.1.9/noupdate_changes.xml")
44+
openupgrade.m2o_to_x2m(env.cr, env["crm.stage"], "crm_stage", "team_ids", "team_id")
45+
_migrate_lead_mobile(env)
46+
_won_stage_field(env)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---Models in module 'crm'---
2+
---Fields in module 'crm'---
3+
crm / crm.lead / commercial_partner_id (many2one): NEW relation: res.partner, hasdefault: compute, stored: False
4+
# NOTHING TO DO
5+
6+
crm / crm.lead / mobile (char) : DEL
7+
# DONE: if phone is empty and mobile not set phone with mobile
8+
9+
crm / crm.lead / title (many2one) : DEL relation: res.partner.title
10+
# NOTHING TO DO
11+
12+
crm / crm.lead / won_status (selection) : NEW selection_keys: ['lost', 'pending', 'won'], isfunction: function, stored
13+
#DONE: set to prevent massive compute
14+
15+
crm / crm.lead.scoring.frequency.field / color (integer) : NEW hasdefault: default
16+
crm / crm.stage / color (integer) : NEW
17+
# NOTHING TO DO
18+
19+
crm / crm.stage / rotting_threshold_days (integer): NEW hasdefault: default
20+
# NOTHING TO DO: default is set to 0 to keep old behavoir
21+
22+
crm / crm.stage / team_id (many2one) : DEL relation: crm.team
23+
crm / crm.stage / team_ids (many2many) : NEW relation: crm.team
24+
# Done: Transform m2o to m2m
25+
26+
crm / crm.team.member / assignment_domain_preferred (char): NEW
27+
crm / res.users / target_sales_done (integer) : DEL
28+
crm / res.users / target_sales_won (integer) : DEL
29+
# NOTHING TO DO
30+
31+
---XML records in module 'crm'---
32+
NEW ir.actions.act_window: crm.mail_followers_edit_action_from_lead
33+
NEW ir.model.constraint: crm.constraint_crm_lead_create_date_team_id_idx
34+
NEW ir.model.constraint: crm.constraint_crm_lead_default_order_idx
35+
NEW ir.model.constraint: crm.constraint_crm_lead_user_id_team_id_type_index
36+
DEL ir.ui.view: crm.crm_lead_partner_kanban_view
37+
# NOTHING TO DO

0 commit comments

Comments
 (0)