Merge lp:~therp-nl/openupgrade-addons/6.1-migrate_email_composition_actions into lp:openupgrade-addons/6.1

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 6607
Proposed branch: lp:~therp-nl/openupgrade-addons/6.1-migrate_email_composition_actions
Merge into: lp:openupgrade-addons/6.1
Diff against target: 97 lines (+65/-10)
2 files modified
email_template/migrations/6.1.1.1/post-migration.py (+61/-0)
email_template/migrations/6.1.1.1/pre-migration.py (+4/-10)
To merge this branch: bzr merge lp:~therp-nl/openupgrade-addons/6.1-migrate_email_composition_actions
Reviewer Review Type Date Requested Status
OpenUpgrade Committers Pending
Review via email: mp+130099@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'email_template/migrations/6.1.1.1/post-migration.py'
2--- email_template/migrations/6.1.1.1/post-migration.py 1970-01-01 00:00:00 +0000
3+++ email_template/migrations/6.1.1.1/post-migration.py 2012-10-17 12:11:24 +0000
4@@ -0,0 +1,61 @@
5+# -*- coding: utf-8 -*-
6+##############################################################################
7+#
8+# OpenERP, Open Source Management Solution
9+# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU Affero General Public License as
13+# published by the Free Software Foundation, either version 3 of the
14+# License, or (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU Affero General Public License for more details.
20+#
21+# You should have received a copy of the GNU Affero General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+##############################################################################
25+
26+import pooler, logging
27+from openerp import SUPERUSER_ID
28+from openerp.tools.safe_eval import safe_eval
29+from openerp.openupgrade import openupgrade
30+
31+def update_actions(cr, pool):
32+ """
33+ Update act windows that trigger an email form action. The template id
34+ is encloded differently in the action's context and the name and view_id of the
35+ wizard has changed as well.
36+ """
37+ cr.execute("""
38+ SELECT id, context FROM ir_act_window
39+ WHERE res_model = 'email_template.send.wizard'
40+ """)
41+ data_pool = pool.get('ir.model.data')
42+ view_id = data_pool.get_object_reference(
43+ cr, SUPERUSER_ID, 'mail', 'email_compose_message_wizard_form')[1]
44+ for row in cr.fetchall():
45+ try:
46+ old_context = safe_eval(row[1] or {}, {'active_id': False, 'active_ids': False})
47+ if old_context.get('template_id'):
48+ new_context = (
49+ "{'mail.compose.message.mode':'mass_mail', "
50+ "'mail.compose.template_id' : %s}" % (old_context['template_id']))
51+ openupgrade.logged_query(cr, """
52+ UPDATE ir_act_window
53+ SET res_model = %s,
54+ view_id = %s,
55+ context = %s
56+ WHERE id = %s
57+ """, ('mail.compose.message', view_id, new_context, row[0]))
58+ except NameError, e:
59+ logger = logging.getLogger('OpenUpgrade')
60+ logger.warn('Could not evaluate %s: %s', old_context, e)
61+
62+@openupgrade.migrate()
63+def migrate(cr, version):
64+ pool = pooler.get_pool(cr.dbname)
65+ update_actions(cr, pool)
66
67=== modified file 'email_template/migrations/6.1.1.1/pre-migration.py'
68--- email_template/migrations/6.1.1.1/pre-migration.py 2012-06-19 09:34:23 +0000
69+++ email_template/migrations/6.1.1.1/pre-migration.py 2012-10-17 12:11:24 +0000
70@@ -19,8 +19,6 @@
71 #
72 ##############################################################################
73
74-import os
75-from osv import osv
76 import logging
77 from openerp.openupgrade import openupgrade
78
79@@ -59,14 +57,10 @@
80 "FROM email_template_account WHERE "
81 "email_template.from_account = email_template_account.id")
82
83+@openupgrade.migrate()
84 def migrate(cr, version):
85 if not version:
86 return
87- try:
88- logger.info("%s called", me)
89- if not openupgrade.column_exists(cr, 'email_template', 'user_signature'):
90- openupgrade.rename_columns(cr, column_renames)
91- fix_email_from(cr)
92- openupgrade.delete_model_workflow(cr, 'email_template.account')
93- except Exception, e:
94- raise osv.except_osv("OpenUpgrade", '%s: %s' % (me, e))
95+ openupgrade.rename_columns(cr, column_renames)
96+ fix_email_from(cr)
97+ openupgrade.delete_model_workflow(cr, 'email_template.account')

Subscribers

People subscribed via source and target branches