[19.0][OU-ADD] crm: Migration scripts#5706
Conversation
797fb16 to
73525be
Compare
|
/ocabot migration crm Depends on :
|
aa5b185 to
6648cdb
Compare
6648cdb to
bbe8e93
Compare
| # NOTHING TO DO | ||
|
|
||
| crm / crm.lead / mobile (char) : DEL | ||
| # DONE: if phone is empty and mobile not set phone with mobile |
There was a problem hiding this comment.
I think we should concatenate the mobile in the pone field in case both exist, or write it on the internal notes to not lose data. And put if done in pre-migration or post-migration.
There was a problem hiding this comment.
I had the feeling more case can appear so I tag it as case 1. If we concatenate that, can this cause trouble with phone_validation ?
There was a problem hiding this comment.
Well, not really, as that module only format the numbers, not block them, and they are already formatted.
| # NOTHING TO DO | ||
|
|
||
| crm / crm.lead / won_status (selection) : NEW selection_keys: ['lost', 'pending', 'won'], isfunction: function, stored | ||
| #DONE: set to prevent massive compute |
There was a problem hiding this comment.
| #DONE: set to prevent massive compute | |
| # DONE: pre-migration: pre-created column and set it to prevent massive computation |
There was a problem hiding this comment.
And I see you have done it on post-migration, so this is not preventing anything.
|
|
||
| crm / crm.stage / team_id (many2one) : DEL relation: crm.team | ||
| crm / crm.stage / team_ids (many2many) : NEW relation: crm.team | ||
| # Done: Transform m2o to m2m |
There was a problem hiding this comment.
| # Done: Transform m2o to m2m | |
| # DONE: post-migration: Transform m2o to m2m |
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| # do not load noupdate_changes.xml, because all entries are problematic | ||
| # the necessary changes are done manually in the _load_data_* functions below |
There was a problem hiding this comment.
Why the color loading in the stages is problematic? cc @hbrunn
There was a problem hiding this comment.
I assume that is because what happens if those records were eliminated by the user, but in this can be manged by the https://github.com/OCA/openupgradelib/blob/ac165a1dccd1fba4f09fb15c194420cdaa4672af/openupgradelib/openupgrade.py#L434
Am i wrong?
There was a problem hiding this comment.
it's indeed problematic when the stages are deleted. for this hack to be active, you need to pass mode='init_no_create', and then also pass an xml transformation to remove overwriting the config parameter. also a way to go, but not really simpler than what happens now. would be future proof for subsequent changes to the file though
There was a problem hiding this comment.
OK, the forcecreate="False" parameter is the defining one. Then please:
- Specify the real reasons, not only to mention "conflicting".
- Put the
load_datainstruction, but commented, to give context.
bbe8e93 to
fe07ea0
Compare
fe07ea0 to
4d7461b
Compare
|
Changes Done.
|
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE crm_lead | ||
| SET phone = mobile | ||
| WHERE (phone IS NULL OR phone = '') | ||
| AND (mobile IS NOT NULL AND mobile != '') | ||
| """, | ||
| ) | ||
| # Case 2: both phone and mobile exist and differ → concatenate them | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE crm_lead | ||
| SET phone = phone || ' / ' || mobile | ||
| WHERE phone IS NOT NULL AND phone != '' | ||
| AND mobile IS NOT NULL AND mobile != '' | ||
| AND btrim(phone) != btrim(mobile) | ||
| """, |
There was a problem hiding this comment.
It can be done in one shot:
| openupgrade.logged_query( | |
| env.cr, | |
| """ | |
| UPDATE crm_lead | |
| SET phone = mobile | |
| WHERE (phone IS NULL OR phone = '') | |
| AND (mobile IS NOT NULL AND mobile != '') | |
| """, | |
| ) | |
| # Case 2: both phone and mobile exist and differ → concatenate them | |
| openupgrade.logged_query( | |
| env.cr, | |
| """ | |
| UPDATE crm_lead | |
| SET phone = phone || ' / ' || mobile | |
| WHERE phone IS NOT NULL AND phone != '' | |
| AND mobile IS NOT NULL AND mobile != '' | |
| AND btrim(phone) != btrim(mobile) | |
| """, | |
| openupgrade.logged_query( | |
| env.cr, | |
| """ | |
| UPDATE crm_lead | |
| SET phone = CONCAT(COALESCE(phone, ''), mobile) | |
| WHERE COELESCE(mobile, '') != '' | |
| """, | |
| ) |
| [ | ||
| ("crm.lead", "won_status", "selection", None, "crm_lead"), | ||
| ], |
There was a problem hiding this comment.
| [ | |
| ("crm.lead", "won_status", "selection", None, "crm_lead"), | |
| ], | |
| [("crm.lead", "won_status", "selection", "pending", "crm_lead")], |
| UPDATE crm_lead cl | ||
| SET won_status = CASE | ||
| WHEN cl.probability = 100 | ||
| AND cs.is_won = TRUE | ||
| THEN 'won' | ||
| WHEN cl.active = FALSE | ||
| AND cl.probability = 0 | ||
| THEN 'lost' | ||
| ELSE 'pending' | ||
| END | ||
| FROM crm_lead cl2 | ||
| LEFT JOIN crm_stage cs ON cs.id = cl2.stage_id | ||
| WHERE cl2.id = cl.id |
There was a problem hiding this comment.
As we are already initializing all of them to "pending", just do 2 updates for the rest (note the changes in the boolean conditions):
UPDATE crm_lead cl
SET won_status = 'won'
FROM crm_stage cs
WHERE cs.id = cl.stage_id
AND cs.is_won
AND cl.probability = 100
UPDATE crm_lead cl
SET won_status = 'lost'
WHERE NOT cl.active
AND cl.probability = 0
cc @Tecnativa TT58614
@pedrobaeza