Skip to content

Commit

Permalink
Merge pull request OCA#505 from savoirfairelinux/8.0_email_template
Browse files Browse the repository at this point in the history
[8.0] Convert email server actions to email.template
  • Loading branch information
StefanRijnhart authored Jun 14, 2016
2 parents b0da369 + 821899b commit bd4057d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions addons/email_template/migrations/8.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux (<https://www.savoirfairelinux.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from psycopg2.extensions import AsIs
from openerp.openupgrade import openupgrade

from openerp import SUPERUSER_ID
from openerp.api import Environment


_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(cr, version):
if not version:
return
env = Environment(cr, SUPERUSER_ID, {})
convert_action_mail_server_email(env)


def convert_action_mail_server_email(env):
def convert_body(body):
return body.replace("[[", "${").replace("]]", "}")

def convert_subject(subject):
subject = subject.strip()
if subject.startswith('object.'):
subject = "${%s}" % subject
return subject

actions = env['ir.actions.server'].search([
('state', '=', 'email'),
('template_id', '=', False),
])

_logger.info(
'Transfering existing ir.actions.server emails to '
'email templates.'
)

for action in actions:

subject_column = openupgrade.get_legacy_name('subject')

env.cr.execute(
"""
SELECT email, %s, message
FROM ir_act_server
WHERE id = %s
""", (AsIs(subject_column), action.id, ))

(email, subject, message) = env.cr.fetchone()

email_template = env['email.template'].create({
'name': action.name,
'model_id': action.model_id.id,
'email_from': convert_subject(email),
'subject': convert_body(subject),
'body_html': convert_body(message),
})

action.template_id = email_template.id
3 changes: 3 additions & 0 deletions addons/email_template/migrations/8.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
column_renames = {
'email_template': [
('email_recipients', 'partner_to'),
],
'ir_act_server': [
('subject', None),
]
}

Expand Down

0 comments on commit bd4057d

Please sign in to comment.