Merge lp:~sylvain-legal/openupgrade-addons/migration-analytic into lp:openupgrade-addons

Proposed by Sylvain LE GAL (GRAP)
Status: Rejected
Rejected by: Holger Brunn (Therp)
Proposed branch: lp:~sylvain-legal/openupgrade-addons/migration-analytic
Merge into: lp:openupgrade-addons
Diff against target: 143 lines (+129/-0)
3 files modified
analytic/migrations/7.0.1.1/openupgrade_analysis_worker.txt (+34/-0)
analytic/migrations/7.0.1.1/post-migration.py (+64/-0)
analytic/migrations/7.0.1.1/pre-migration.py (+31/-0)
To merge this branch: bzr merge lp:~sylvain-legal/openupgrade-addons/migration-analytic
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Approve
Stefan Rijnhart (Opener) Approve
Review via email: mp+174751@code.launchpad.net

Commit message

[ADD] migration scripts for 'analytic' module.

Description of the change

Hi.

[ADD] migration scripts for 'analytic' module.
- pre-migration.py ;
- post-migration.py ("empty")
- openupgrade_analysis_worker.txt. (notes about analysis)

Warning : do not merge before an other branch is merged in an other project (openupgrade-server), because 'pre-migration.py' use get_partner_id_from_partner_address_id() function.

'OpenUpgrade-server' Prerequisite Branch :
(https://code.launchpad.net/~sylvain-legal/openupgrade-server/three-functions-for-addons-migration/+merge/174668)

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks! Here are my comments,

- The analytic sequences are not new but come from the account module, and need to be renamed here because analytic is a dependency of account.
- 'type' is now required. You may want to replace empty values in the database with the new default 'normal' just to be sure.
- 'manager_id' is set by an onchange method to the partner's salesperson ('user_id'). It would be nice if you could retrieve and store this value for all existing analytic accounts that have a partner_id (in the post script).

Keep up the great work, Sylvain!

review: Needs Fixing
Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Thanks for your quick review !

1/ You're right.
--> changed commited.

2/ I'm not sure. To test I did the following :
A : in a 6.1 : "update account_analytic_account set type=null; "
B : migration -> 7.0
C : the 'type' values are 'normal' ; --> OK
A' in a 6.1 : "update account_analytic_account set type='wrong_value'; "
B' : migration -> 7.0
C' : the 'type' value still is 'wrong_value' ; --> FAILED
Conclusion, if the database values are OK, the migration will do the following :
- Null, 'normal' -> 'normal'
- 'view' -> 'view'

3/ You're right too !
--> changed commited.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks, you are right on 2: newly required fields with a default value are filled automatically. Approved!

review: Approve
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Sylvain,

because of your holidays I took the liberty again to refactor your branch to adapt to the API change that I suggested:
https://code.launchpad.net/~therp-nl/openupgrade-addons/migration-analytic/+merge/175796

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

approve, but rejecting this MP as it's superseded by Stefan's one

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'analytic/migrations/7.0.1.1/openupgrade_analysis_worker.txt'
2--- analytic/migrations/7.0.1.1/openupgrade_analysis_worker.txt 1970-01-01 00:00:00 +0000
3+++ analytic/migrations/7.0.1.1/openupgrade_analysis_worker.txt 2013-07-15 16:52:26 +0000
4@@ -0,0 +1,34 @@
5+---analytic---
6+analytic / account.analytic.account / contact_id (many2one) : DEL relation: res.partner.address
7+# In 6.1, there is Two field partner_id [res.partner] and contact_id [res.partner.adress]
8+# In 7.0, there is on contact_id [res.partner] due to the merging of concept.
9+# -> Merging choice : select the old 'contact_id' (more precise) to fill 'partner_id' if 'contact_id' is defined.
10+
11+analytic / account.analytic.account / template_id (many2one) : NEW relation: account.analytic.account
12+# --> New concept available only in case of Account_analytic_accont.type="contract" : OK. (because 'contract' is new keys)
13+
14+analytic / account.analytic.account / manager_id (many2one) : NEW relation: res.users
15+# --> New concept: OK
16+
17+analytic / account.analytic.account / message_ids (one2many) : NEW relation: mail.message
18+# --> New concept: OK
19+
20+analytic / account.analytic.account / type (selection) : selection_keys is now '['contract', 'normal', 'template', 'view']' ('['normal', 'view']')
21+# New keys in selection : OK.
22+
23+analytic / account.analytic.account / type (selection) : now required, default = normal
24+# Value is required with default value : OK
25+
26+
27+new xml-id of model mail.message.subtype: analytic.mt_account_closed # mail.message.subtype is NEW : OK.
28+new xml-id of model mail.message.subtype: analytic.mt_account_opened # mail.message.subtype is NEW : OK.
29+new xml-id of model mail.message.subtype: analytic.mt_account_pending # mail.message.subtype is NEW : OK.
30+
31+new xml-id of model ir.sequence.type: analytic.seq_type_analytic_account_main
32+### previously in module "account" and named "seq_type_analytic_account". Rename xml : OK
33+
34+new xml-id of model ir.sequence: analytic.seq_analytic_account_base
35+### previously in module "account" and named "seq_analytic_account". Rename xml : OK
36+
37+### System XML IDs belows : (Nothing to do)
38+new xml-id of model ir.ui.view: analytic.view_account_analytic_account_form
39
40=== added file 'analytic/migrations/7.0.1.1/post-migration.py'
41--- analytic/migrations/7.0.1.1/post-migration.py 1970-01-01 00:00:00 +0000
42+++ analytic/migrations/7.0.1.1/post-migration.py 2013-07-15 16:52:26 +0000
43@@ -0,0 +1,64 @@
44+# -*- coding: utf-8 -*-
45+##############################################################################
46+#
47+# OpenERP, Open Source Management Solution
48+# This migration script copyright (C) 2013-today Sylvain LE GAL
49+#
50+# This program is free software: you can redistribute it and/or modify
51+# it under the terms of the GNU Affero General Public License as
52+# published by the Free Software Foundation, either version 3 of the
53+# License, or (at your option) any later version.
54+#
55+# This program is distributed in the hope that it will be useful,
56+# but WITHOUT ANY WARRANTY; without even the implied warranty of
57+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58+# GNU Affero General Public License for more details.
59+#
60+# You should have received a copy of the GNU Affero General Public License
61+# along with this program. If not, see <http://www.gnu.org/licenses/>.
62+#
63+##############################################################################
64+
65+from openupgrade import openupgrade
66+from openupgrade import openupgrade_70
67+from openerp import pooler, SUPERUSER_ID
68+
69+def migrate_partner_address(cr, pool):
70+ """
71+ Manage partner changes in 'account.analytic.account'.
72+ Use obsolete 'contact_id' field to fill 'partner_id' if 'contact_id' is not null.
73+ Otherwise, use partner_id.
74+ """
75+ analytic_obj = pool.get('account.analytic.account')
76+ cr.execute("""
77+ SELECT id, contact_id
78+ FROM account_analytic_account
79+ WHERE contact_id is not null; """)
80+ for row in cr.dictfetchall():
81+ vals = {
82+ 'partner_id': openupgrade_70.get_partner_id_from_partner_address_id(cr, row['contact_id']),
83+ }
84+ analytic_obj.write(cr, SUPERUSER_ID, row['id'], vals)
85+
86+def fill_manager_id(cr, pool):
87+ """
88+ Fill the new field 'manager_id' depending on account_analytic_account.partner_id.user_id
89+ """
90+ analytic_obj = pool.get('account.analytic.account')
91+ cr.execute("""SELECT
92+ account_analytic_account.id as id,
93+ res_users.id as manager_id
94+ FROM account_analytic_account
95+ INNER JOIN res_partner on res_partner.id = account_analytic_account.partner_id
96+ INNER JOIN res_users on res_partner.user_id = res_users.id; """)
97+ for row in cr.dictfetchall():
98+ vals = {
99+ 'manager_id' : row['manager_id'],
100+ }
101+ analytic_obj.write(cr, SUPERUSER_ID, row['id'], vals)
102+
103+@openupgrade.migrate()
104+def migrate(cr, version):
105+ pool = pooler.get_pool(cr.dbname)
106+ migrate_partner_address(cr, pool)
107+ fill_manager_id(cr, pool)
108
109=== added file 'analytic/migrations/7.0.1.1/pre-migration.py'
110--- analytic/migrations/7.0.1.1/pre-migration.py 1970-01-01 00:00:00 +0000
111+++ analytic/migrations/7.0.1.1/pre-migration.py 2013-07-15 16:52:26 +0000
112@@ -0,0 +1,31 @@
113+# -*- coding: utf-8 -*-
114+##############################################################################
115+#
116+# OpenERP, Open Source Management Solution
117+# This migration script copyright (C) 2013-today Sylvain LE GAL
118+#
119+# This program is free software: you can redistribute it and/or modify
120+# it under the terms of the GNU Affero General Public License as
121+# published by the Free Software Foundation, either version 3 of the
122+# License, or (at your option) any later version.
123+#
124+# This program is distributed in the hope that it will be useful,
125+# but WITHOUT ANY WARRANTY; without even the implied warranty of
126+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
127+# GNU Affero General Public License for more details.
128+#
129+# You should have received a copy of the GNU Affero General Public License
130+# along with this program. If not, see <http://www.gnu.org/licenses/>.
131+#
132+##############################################################################
133+
134+from openupgrade import openupgrade
135+
136+xmlid_renames = [
137+ ('account.seq_type_analytic_account', 'analytic.seq_type_analytic_account_main'),
138+ ('account.seq_analytic_account', 'analytic.seq_analytic_account_base'),
139+]
140+
141+@openupgrade.migrate()
142+def migrate(cr, version):
143+ openupgrade.rename_xmlids(cr, xmlid_renames)

Subscribers

People subscribed via source and target branches