Skip to content
Merged
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
23 changes: 13 additions & 10 deletions addons/crm/migrations/10.0.1.0/openupgrade_analysis_work.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,36 @@ crm / crm.activity / activity_2_id (many2one) : DEL re
crm / crm.activity / activity_3_id (many2one) : DEL relation: crm.activity
crm / crm.activity / recommended_activity_ids (many2many): NEW relation: crm.activity
crm / crm.activity / preceding_activity_ids (many2many): NEW relation: crm.activity
# TODO: pre-migration: copy columns
# TODO: post-migration: convert activity 1,2,3 to recommended_activity_ids
# Done: rename columns on pre-migration for adding them to the new many2many on post-migration

crm / crm.lead / last_activity_id (many2one) : DEL relation: crm.activity
# Done: Preserve column if needed for other module

crm / crm.lead / website_message_ids (one2many): DEL relation: mail.message
# NOTHING TO DO
# Nothing to do

crm / crm.lead.tag / team_id (many2one) : DEL relation: crm.team
# TODO: Merge resulting duplicated records
# Done: Preserve column if needed for other module.
# No merging is done because it's better to have tags with the same label than to merge them and
# break other modules that use these tags.

crm / crm.stage / team_id (many2one) : NEW relation: crm.team
crm / crm.stage / team_ids (many2many) : DEL relation: crm.team
crm / crm.team / stage_ids (many2many) : DEL relation: crm.stage
# TODO: pre-migration: copy table
# TODO: post-migration: if the stage applied to multiple teams, do not set it
# . If it applied to just one team, set to that one.
# Done: Assign a team on the field team_id if len(team_ids) == 1

crm / crm.stage / type (selection) : DEL required: required, selection_keys: ['both', 'lead', 'opportunity'], req_default: both
# NOTHING TO DO
# Done: Preserve column if needed for other module.

crm / res.partner / team_id (False) : NEW mode: modify
crm / res.users / team_id (False) : NEW mode: modify
# NOTHING TO DO
# Nothing to do: They can be False by default

---XML records in module 'crm'---
NEW crm.stage: crm.stage_lead4
DEL crm.stage: crm.stage_lead5
# Done: Remove possible demo XML-ID and rename XML-ID

NEW ir.actions.act_window: crm.create_opportunity_simplified
NEW ir.actions.act_window: crm.crm_activity_log_action
NEW ir.actions.act_window: crm.crm_activity_report_action_tree
Expand Down Expand Up @@ -73,4 +76,4 @@ DEL web.tip: crm.crm_tip_2
DEL web.tip: crm.crm_tip_4
DEL web.tip: crm.crm_tip_5
DEL web.tip: crm.crm_tip_6
# NOTHING TO DO
# Nothing to do as noupdate=0 records
46 changes: 46 additions & 0 deletions addons/crm/migrations/10.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade


def _convert_next_activities(env):
columns = [
'activity_1_id',
'activity_2_id',
'activity_3_id',
]
for column in columns:
openupgrade.m2o_to_x2m(
env.cr, env['crm.activity'], 'crm_activity',
'recommended_activity_ids', openupgrade.get_legacy_name(column),
)


def _assign_stage_team(env):
"""Assign the team on the stage if there was previously only one team
assigned.
"""
env.cr.execute(
"""UPDATE crm_stage
SET team_id=team_stage_rel.team_id
FROM (
SELECT team_id, stage_id
FROM (
SELECT team_id, stage_id,
row_number()
OVER (partition BY stage_id ORDER BY stage_id) AS rnum
FROM crm_team_stage_rel
) t
WHERE t.rnum = 1
) AS team_stage_rel
WHERE id=team_stage_rel.stage_id
"""
)


@openupgrade.migrate()
def migrate(env, version):
_convert_next_activities(env)
_assign_stage_team(env)
41 changes: 41 additions & 0 deletions addons/crm/migrations/10.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade

_column_renames = {
'crm_activity': [
('activity_1_id', None),
('activity_2_id', None),
('activity_3_id', None),
],
'crm_lead': [
('last_activity_id', None),
],
'crm_lead_tag': [
('team_id', None),
],
'crm_stage': [
('type', None),
],
}

_xmlid_renames = [
('crm.stage_lead5', 'crm.stage_lead4'),
]


def _rename_xml_ids(env):
# As v9 demo data contains already a crm.stage_lead4, we need to remove
# previously that XML-ID in case it exists
env.cr.execute(
"DELETE FROM ir_model_data WHERE module='crm' AND name='stage_lead4'"
)
openupgrade.rename_xmlids(env.cr, _xmlid_renames)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_columns(env.cr, _column_renames)
_rename_xml_ids(env)
24 changes: 24 additions & 0 deletions addons/crm/migrations/10.0.1.0/tests/test_crm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# coding: utf-8
from openerp.tests import common


class TestCrm(common.TransactionCase):

def test_crm(self):
# Check single team is assigned
self.assertEqual(
self.env.ref('crm.stage_lead2').team_id,
self.env.ref('sales_team.team_sales_department')
)
# Check next activities field is filled
activity = self.env.ref('crm.crm_activity_demo_make_quote')
self.assertEqual(
activity.recommended_activity_ids,
self.env.ref('crm.crm_activity_demo_followup_quote')
)
activity = self.env.ref('crm.crm_activity_data_meeting')
self.assertEqual(
activity.recommended_activity_ids,
self.env.ref('crm.crm_activity_data_call') +
self.env.ref('crm.crm_activity_data_email')
)
6 changes: 4 additions & 2 deletions odoo/addons/base/ir/ir_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _drop_table(self):
for model in self:
# OpenUpgrade: do not run the new table cleanup
openupgrade.message(
cr, 'Unknown', False, False,
self._cr, 'Unknown', False, False,
"Not dropping the table or view of model %s", model.model)
continue
table = self.env[model.model]._table
Expand Down Expand Up @@ -437,7 +437,9 @@ def _drop_column(self):
# OpenUpgrade: do not drop columns
openupgrade.message(
self._cr, 'Unknown', False, False,
"Not dropping the column of field %s of model %s", field.name, field.model)
"Not dropping the column of field %s of model %s", field.name,
field.model,
)
continue
model = self.env[field.model]
self._cr.execute('SELECT relkind FROM pg_class WHERE relname=%s', (model._table,))
Expand Down
7 changes: 6 additions & 1 deletion odoo/addons/base/migrations/10.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ def migrate(cr, version):
end,
'res.lang', id
from res_lang''')
# set some obsolete modules to auto uninstall
# set some obsolete modules to auto uninstall (and remove dependencies)
cr.execute(
'''update ir_module_module
set state = 'to remove'
where name in ('web_tip', 'web_view_editor')
''')
cr.execute(
"""DELETE FROM ir_module_module_dependency
WHERE name in ('web_tip', 'web_view_editor')
"""
)
2 changes: 1 addition & 1 deletion odoo/openupgrade/doc/source/modules90-100.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ missing in the new release are marked with |del|.
+-----------------------------------+-----------------------------------+
| |new| contacts | |
+-----------------------------------+-----------------------------------+
|crm | |
|crm | Done |
+-----------------------------------+-----------------------------------+
| |del| crm_claim | |
+-----------------------------------+-----------------------------------+
Expand Down