Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/openupgrade-addons/7.0-mail into lp:openupgrade-addons.
Requested reviews: Holger Brunn (Therp) (hbrunn): code review For more details, see: https://code.launchpad.net/~therp-nl/openupgrade-addons/7.0-mail/+merge/176010 Migration of the mail module, including the nice HTMLifier code from Credativ's abandoned contribution (https://code.launchpad.net/~credativ/openupgrade-addons/7.0/+merge/170411) -- https://code.launchpad.net/~therp-nl/openupgrade-addons/7.0-mail/+merge/176010 Your team OpenUpgrade Committers is subscribed to branch lp:openupgrade-addons.
=== added file 'email_template/migrations/7.0.1.1/openupgrade_analysis_working.txt' --- email_template/migrations/7.0.1.1/openupgrade_analysis_working.txt 1970-01-01 00:00:00 +0000 +++ email_template/migrations/7.0.1.1/openupgrade_analysis_working.txt 2013-07-23 18:20:38 +0000 @@ -0,0 +1,46 @@ +---Fields in module 'email_template'--- +### To convert to body_html if that is empty +email_template / email.template / body_text (text) : DEL + +### Ignore useless fields from former inherit on mail.message +email_template / email.template / date (datetime) : DEL +email_template / email.template / headers (text) : DEL +email_template / email.template / message_id (char) : DEL +email_template / email.template / original (binary) : DEL +email_template / email.template / partner_id (many2one) : DEL relation: res.partner +email_template / email.template / references (text) : DEL +email_template / email.template / res_id (integer) : DEL +email_template / email.template / state (selection) : DEL selection_keys: ['cancel', 'exception', 'outgoing', 'received', 'sent'] +email_template / email.template / subtype (char) : DEL +email_template / email.template / user_id (many2one) : DEL relation: res.users + +### Mention the loss of BCCs in the user notes +email_template / email.template / email_bcc (char) : DEL + +### Ignore new field (list of partner ids?) +email_template / email.template / email_recipients (char) : NEW + +### Ignore previously unused field +email_template / email.template / track_campaign_item (boolean) : DEL + +### Ignore this TransientModel. +### The analysis cannot distinguish Models from TransientModels that inherit from Model +email_template / email_template.preview / body_text (text) : DEL +email_template / email_template.preview / date (datetime) : DEL +email_template / email_template.preview / email_bcc (char) : DEL +email_template / email_template.preview / email_recipients (char) : NEW +email_template / email_template.preview / headers (text) : DEL +email_template / email_template.preview / message_id (char) : DEL +email_template / email_template.preview / original (binary) : DEL +email_template / email_template.preview / partner_id (many2one) : DEL relation: res.partner +email_template / email_template.preview / references (text) : DEL +email_template / email_template.preview / state (selection) : DEL selection_keys: ['cancel', 'exception', 'outgoing', 'received', 'sent'] +email_template / email_template.preview / subtype (char) : DEL +email_template / email_template.preview / track_campaign_item (boolean) : DEL +email_template / email_template.preview / user_id (many2one) : DEL relation: res.users +# Ignore this TransientModel +email_template / mail.compose.message / template_id (selection) : NEW selection_keys: function +---XML records in module 'email_template'--- +DEL ir.model.access: email_template.access_email_template_manager +DEL ir.model.access: email_template.access_email_template_preview_system +NEW ir.ui.view: email_template.res_partner_opt_out_search === added file 'email_template/migrations/7.0.1.1/post-migration.py' --- email_template/migrations/7.0.1.1/post-migration.py 1970-01-01 00:00:00 +0000 +++ email_template/migrations/7.0.1.1/post-migration.py 2013-07-23 18:20:38 +0000 @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Credativ Ltd (<http://credativ.co.uk>) +# (C) 2013 Therp BV (<http://therp.nl>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from openerp.openupgrade import openupgrade +from openerp.tools.mail import plaintext2html + +def convert_mail_bodies(cr): + """ + Convert plain bodies to sanitized html. + """ + cr.execute( + "SELECT id, %(body_text)s FROM email_template " + "WHERE body_html IS NULL AND body_html != '' AND body_text IS NOT NULL" % { + 'body_text': openupgrade.get_legacy_name('body_text'), + }) + for row in cr.fetchall(): + body = plaintext2html(row[1]) + cr.execute("UPDATE mail_message SET body_html = %s WHERE id = %s", body, row[0]) + + # Migrate translations of text templates + cr.execute( + """ + SELECT tr_text.res_id, tr_text.lang, tr_text.value, + (SELECT COUNT(*) FROM ir_translation tr_count + WHERE tr_count.type = 'model' + AND tr_count.name = 'email.template,body_html' + AND tr_count.res_id = tr_text.res_id + AND tr_count.lang = tr_text.lang) as count + FROM ir_translation tr_text + WHERE type = 'model' + AND name = 'email.template,body_text' + AND NOT EXISTS ( + SELECT tr_html.id + FROM ir_translation tr_html + WHERE tr_html.type = 'model' + AND tr_html.name = 'email.template,body_html' + AND tr_text.res_id = tr_html.res_id + AND tr_text.lang = tr_html.lang + AND (tr_html.value is not NULL OR tr_html.value != '') + ) + """) + + for (res_id, lang, value, count) in cr.fetchall(): + body = plaintext2html(value) + if count: + cr.execute( + """ + UPDATE ir_translation + SET value = %s + WHERE type = 'model' + AND name = 'email.template,body_html' + AND res_id = %s + AND lang = %s + """, (body, res_id, lang)) + else: + cr.execute( + """ + INSERT INTO ir_translation + (lang, name, type, res_id, value, src) + VALUES ( + %s, 'email.template,body_html', 'model', %s, %s, + (SELECT body_html + FROM email_template et + WHERE et.id = %s)) + """, (lang, res_id, body, res_id)) + [email protected]() +def migrate(cr, version): + convert_mail_bodies(cr) + === added file 'email_template/migrations/7.0.1.1/pre-migration.py' --- email_template/migrations/7.0.1.1/pre-migration.py 1970-01-01 00:00:00 +0000 +++ email_template/migrations/7.0.1.1/pre-migration.py 2013-07-23 18:20:38 +0000 @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (<http://therp.nl>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from openerp.openupgrade import openupgrade + +column_renames = { + 'email.template': [ + # Existing fields to ignore + # Existing fields to transform + ('body_text', None), + ]} + [email protected]() +def migrate(cr, version): + openupgrade.rename_columns(cr, column_renames) === added file 'email_template/migrations/7.0.1.1/user_notes.txt' --- email_template/migrations/7.0.1.1/user_notes.txt 1970-01-01 00:00:00 +0000 +++ email_template/migrations/7.0.1.1/user_notes.txt 2013-07-23 18:20:38 +0000 @@ -0,0 +1,1 @@ +You can no longer use BCC recipients in email templates. Also, text emails are converted to html now. Any existing templates will be migrated. === added file 'fetchmail/migrations/7.0.1.0/post-migration.py' --- fetchmail/migrations/7.0.1.0/post-migration.py 1970-01-01 00:00:00 +0000 +++ fetchmail/migrations/7.0.1.0/post-migration.py 2013-07-23 18:20:38 +0000 @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (<http://therp.nl>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from openerp.openupgrade import openupgrade + +def move_fetchmail_server_id(cr): + """ + Fetchmail now relates to mail.mail, not mail.message + """ + cr.execute( + "UPDATE mail_mail SET fetchmail_server_id = " + " mail_message.%(fetchmail_server_id)s " + "FROM mail_mail, mail_message " + "WHERE mail_mail.mail_message_id = mail_message.id " + " AND mail_message.%(fetchmail_server_id)s IS NOT NULL" % { + 'fetchmail_server_id': openupgrade.get_legacy_name( + 'fetchmail_server_id'), + }) + [email protected]() +def migrate(cr, version): + move_fetchmail_server_id(cr) === added file 'fetchmail/migrations/7.0.1.0/pre-migration.py' --- fetchmail/migrations/7.0.1.0/pre-migration.py 1970-01-01 00:00:00 +0000 +++ fetchmail/migrations/7.0.1.0/pre-migration.py 2013-07-23 18:20:38 +0000 @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (<http://therp.nl>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from openerp.openupgrade import openupgrade + +column_renames = { + 'mail.message': [ + # Existing fields to ignore + # Existing fields to transform + ('fetchmail_server_id', None), + ]} + [email protected]() +def migrate(cr, version): + openupgrade.rename_columns(cr, column_renames) === added file 'fetchmail/migrations/7.0.1.0/user_notes.txt' --- fetchmail/migrations/7.0.1.0/user_notes.txt 1970-01-01 00:00:00 +0000 +++ fetchmail/migrations/7.0.1.0/user_notes.txt 2013-07-23 18:20:38 +0000 @@ -0,0 +1,1 @@ +This migration script adapts existing emails to technical changes. === added file 'mail/migrations/7.0.1.0/data.xml' --- mail/migrations/7.0.1.0/data.xml 1970-01-01 00:00:00 +0000 +++ mail/migrations/7.0.1.0/data.xml 2013-07-23 18:20:38 +0000 @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + <record id="ir_cron_mail_scheduler_action"> + <field eval="'mail.mail'" name="model"/> + </record> + </data> +</openerp> + === added file 'mail/migrations/7.0.1.0/openupgrade_analysis_working.txt' --- mail/migrations/7.0.1.0/openupgrade_analysis_working.txt 1970-01-01 00:00:00 +0000 +++ mail/migrations/7.0.1.0/openupgrade_analysis_working.txt 2013-07-23 18:20:38 +0000 @@ -0,0 +1,213 @@ +---Fields in module 'mail'--- +### Ignore new mail configuration: aliases, followers, groups, message subtypes, notifications +mail / ir.ui.menu / mail_group_id (many2one) : NEW relation: mail.group +mail / mail.alias / alias_defaults (text) : NEW required: required, req_default: {} +mail / mail.alias / alias_force_thread_id (integer): NEW +mail / mail.alias / alias_model_id (many2one) : NEW relation: ir.model, required: required +mail / mail.alias / alias_name (char) : NEW required: required +mail / mail.alias / alias_user_id (many2one) : NEW relation: res.users +mail / mail.followers / partner_id (many2one) : NEW relation: res.partner, required: required +mail / mail.followers / res_id (integer) : NEW +mail / mail.followers / res_model (char) : NEW required: required +mail / mail.followers / subtype_ids (many2many) : NEW relation: mail.message.subtype +mail / mail.group / _inherits (False) : NEW +mail / mail.group / alias_id (many2one) : NEW relation: mail.alias, required: required +mail / mail.group / description (text) : NEW +mail / mail.group / group_ids (many2many) : NEW relation: res.groups +mail / mail.group / group_public_id (many2one) : NEW relation: res.groups +mail / mail.group / image (binary) : NEW +mail / mail.group / menu_id (many2one) : NEW relation: ir.ui.menu, required: required +mail / mail.group / message_ids (one2many) : NEW relation: mail.message +mail / mail.group / name (char) : NEW required: required +mail / mail.group / public (selection) : NEW required: required, selection_keys: ['groups', 'private', 'public'], req_default: groups +mail / mail.message.subtype / default (boolean) : NEW +mail / mail.message.subtype / description (text) : NEW +mail / mail.message.subtype / name (char) : NEW required: required +mail / mail.message.subtype / parent_id (many2one) : NEW relation: mail.message.subtype +mail / mail.message.subtype / relation_field (char) : NEW +mail / mail.message.subtype / res_model (char) : NEW +mail / mail.notification / message_id (many2one) : NEW relation: mail.message, required: required +mail / mail.notification / partner_id (many2one) : NEW relation: res.partner, required: required +mail / mail.notification / read (boolean) : NEW +mail / mail.notification / starred (boolean) : NEW + +### Dealt with split up between mail.message and mail.mail. See below. +mail / mail.mail / _inherits (False) : NEW +mail / mail.mail / auto_delete (boolean) : NEW +mail / mail.mail / body_html (text) : NEW +mail / mail.mail / email_cc (char) : NEW +mail / mail.mail / email_from (char) : NEW +mail / mail.mail / email_to (text) : NEW +mail / mail.mail / mail_message_id (many2one) : NEW relation: mail.message, required: required +mail / mail.mail / mail_server_id (many2one) : NEW relation: ir.mail_server +mail / mail.mail / notification (boolean) : NEW +mail / mail.mail / references (text) : NEW +mail / mail.mail / reply_to (char) : NEW +mail / mail.mail / state (selection) : NEW selection_keys: ['cancel', 'exception', 'outgoing', 'received', 'sent'] +mail / mail.message / attachment_ids (many2many) : NEW relation: ir.attachment +mail / mail.message / author_id (many2one) : NEW relation: res.partner +mail / mail.message / body (html) : NEW +mail / mail.message / child_ids (one2many) : NEW relation: mail.message +mail / mail.message / date (datetime) : NEW +mail / mail.message / email_from (char) : NEW +mail / mail.message / message_id (char) : NEW +mail / mail.message / model (char) : NEW +mail / mail.message / notification_ids (one2many) : NEW relation: mail.notification +mail / mail.message / notified_partner_ids (many2many): NEW relation: res.partner +mail / mail.message / parent_id (many2one) : NEW relation: mail.message +mail / mail.message / partner_ids (many2many) : NEW relation: res.partner +mail / mail.message / res_id (integer) : NEW +mail / mail.message / subject (char) : NEW +mail / mail.message / subtype_id (many2one) : NEW relation: mail.message.subtype +mail / mail.message / type (selection) : NEW selection_keys: ['comment', 'email', 'notification'] +mail / mail.message / vote_user_ids (many2many) : NEW relation: res.users +mail / res.partner / emails (one2many) : DEL relation: mail.message +mail / res.partner / message_ids (one2many) : NEW relation: mail.message +mail / res.partner / notification_email_send (selection): NEW required: required, selection_keys: ['all', 'comment', 'email', 'none'], req_default: function + +### Ignore. Broken output from analysis, but res_users inherit from mail.alias now. The aliases are created at model initialization time +mail / res.users / _inherits (False) : NEW mode: modify +mail / res.users / alias_id (many2one) : NEW relation: mail.alias, required: required + +---XML records in module 'mail'--- +### Ignore interface records +NEW ir.actions.act_window: mail.action_view_followers +NEW ir.actions.act_window: mail.action_view_groups +NEW ir.actions.act_window: mail.action_view_mail_alias +NEW ir.actions.act_window: mail.action_view_mail_mail +NEW ir.actions.act_window: mail.action_view_message_subtype +NEW ir.actions.act_window: mail.action_view_notifications +DEL ir.actions.act_window: mail.act_res_partner_emails +DEL ir.actions.act_window: mail.action_view_mailgate_thread +DEL ir.actions.act_window.view: mail.action_view_mailgate_thread_view1 +DEL ir.actions.act_window.view: mail.action_view_mailgate_thread_view2 +NEW ir.actions.client: mail.action_mail_archives_feeds +NEW ir.actions.client: mail.action_mail_group_feeds +NEW ir.actions.client: mail.action_mail_inbox_feeds +NEW ir.actions.client: mail.action_mail_star_feeds +NEW ir.actions.client: mail.action_mail_to_me_feeds +NEW ir.ui.menu: mail.mail_alias_menu +NEW ir.ui.menu: mail.mail_allgroups +NEW ir.ui.menu: mail.mail_archivesfeeds +NEW ir.ui.menu: mail.mail_feeds +NEW ir.ui.menu: mail.mail_feeds_main +NEW ir.ui.menu: mail.mail_group_root +NEW ir.ui.menu: mail.mail_inboxfeeds +NEW ir.ui.menu: mail.mail_my_stuff +NEW ir.ui.menu: mail.mail_starfeeds +NEW ir.ui.menu: mail.mail_tomefeeds +NEW ir.ui.menu: mail.menu_email_followers +NEW ir.ui.menu: mail.menu_email_notifications +NEW ir.ui.menu: mail.menu_mail_mail +NEW ir.ui.menu: mail.menu_mail_message +NEW ir.ui.menu: mail.menu_message_subtype +DEL ir.ui.menu: mail.menu_email_message +NEW ir.ui.view: mail.mail_wizard_invite_form +NEW ir.ui.view: mail.view_followers_tree +NEW ir.ui.view: mail.view_general_configuration_mail_alias_domain +NEW ir.ui.view: mail.view_group_form +NEW ir.ui.view: mail.view_group_kanban +NEW ir.ui.view: mail.view_group_search +NEW ir.ui.view: mail.view_group_tree +NEW ir.ui.view: mail.view_mail_alias_form +NEW ir.ui.view: mail.view_mail_alias_search +NEW ir.ui.view: mail.view_mail_alias_tree +NEW ir.ui.view: mail.view_mail_form +NEW ir.ui.view: mail.view_mail_message_subtype_form +NEW ir.ui.view: mail.view_mail_search +NEW ir.ui.view: mail.view_mail_subscription_form +NEW ir.ui.view: mail.view_mail_tree +NEW ir.ui.view: mail.view_message_form +NEW ir.ui.view: mail.view_message_search +NEW ir.ui.view: mail.view_message_subtype_tree +NEW ir.ui.view: mail.view_message_tree +NEW ir.ui.view: mail.view_notification_tree +NEW ir.ui.view: mail.view_users_form_mail +NEW ir.ui.view: mail.view_users_form_simple_modif_mail +DEL ir.ui.view: base.view_crm_partner_info_History +DEL ir.ui.view: mail.view_email_message_form +DEL ir.ui.view: mail.view_email_message_search +DEL ir.ui.view: mail.view_email_message_tree +DEL ir.ui.view: mail.view_mailgate_thread_form +DEL ir.ui.view: mail.view_mailgate_thread_tree + +### Ignore new scheduled task +NEW ir.cron: mail.ir_cron_module_update_notification + +### Ignore swap out of access rules +NEW ir.model.access: mail.access_mail_alias_all +NEW ir.model.access: mail.access_mail_alias_system +NEW ir.model.access: mail.access_mail_alias_user +NEW ir.model.access: mail.access_mail_followers_all +NEW ir.model.access: mail.access_mail_followers_system +NEW ir.model.access: mail.access_mail_followers_user +NEW ir.model.access: mail.access_mail_group_all +NEW ir.model.access: mail.access_mail_group_user +NEW ir.model.access: mail.access_mail_mail_all +NEW ir.model.access: mail.access_mail_mail_system +NEW ir.model.access: mail.access_mail_mail_user +NEW ir.model.access: mail.access_mail_message_all +NEW ir.model.access: mail.access_mail_message_subtype_all +NEW ir.model.access: mail.access_mail_message_subtype_system +NEW ir.model.access: mail.access_mail_message_user +NEW ir.model.access: mail.access_mail_notification_all +NEW ir.model.access: mail.access_mail_notification_system +NEW ir.model.access: mail.access_mail_notification_user +NEW ir.model.access: mail.access_mail_thread_all +NEW ir.model.access: mail.access_publisher_warranty_contract_all +DEL ir.model.access: mail.access_mail_message +DEL ir.model.access: mail.access_mail_thread +NEW ir.rule: mail.mail_followers_read_write_own +NEW ir.rule: mail.mail_group_public_and_joined +NEW ir.rule: mail.mail_notification_read_write_own + +### Ignore new configuration data +NEW mail.group: mail.group_all_employees +NEW mail.message: mail.module_install_notification +NEW mail.message.subtype: mail.mt_comment + +### Here is some manual bookkeeping to deal with the split up between +### mail.message and the new mail.mail model. +### Fields in mail.message: +### KEEP ### +# < subject (char, 512) > Keep +# < model (char, 128) > Keep +# < res_id (integer) > Keep +# < date (datetime) > Keep +# < email_from (char) > Keep +# < message_id (char) > Keep +# < attachment_ids (m2m res.attachment) > Keep +### Transform ### +# < body_text (text) > txt2html to 'body' on mail.message if not body_html. DONE +# < body_html (text) > Move to 'body' on mail.message. Also? Move to mail.mail. DONE +# < partner_id (m2o res.partner) > Move to m2m partner_ids. DONE +# < user_id (m2o res.users) > author_id (m2o res.partner). Look up user's partner DONE +# > record_name > call mail_message(_get_record_name) field function after setting model and res_id iff model && res_id DONE +# > type (email, comment, notification) > Set to notification DONE +# > parent_id > ? Lookup by in-reply-to? +### MOVE TO MAIL.MAIL ### +# < mail_server_id (m2o, ir.mail_server) > Move to mail.mail DONE +# < email_to (char) > Move to mail.mail DONE +# < email_cc (char) > Move to mail.mail DONE +# < email_bcc (char) > Move to mail.mail DONE +# < reply_to (char) > Move to mail.mail DONE +# < references (text) > Move to mail.mail DONE +# < state (outgoing, sent, received, exception, cancel) > Move to mail.mail DONE +# < autodelete (burn after sending, not relevant) > Move to mail.mail DONE +### IGNORE ### +# < subtype (char, {html|plain} > Ignore +# < headers (text) > Ignore +# < display_text (text, unstored function). Ignore +# < original (fields.binary, various formats). Ignore +# > child_ids > inverse of parent_id. Ignore +# > notified_partner_ids (m2m res.partner). Ignore +# > notification_ids (o2m mail.notification) > Ignore +# > to_read (bool function). Ignore +# > starred (bool function). Ignore +# > vote_user_ids (m2m res.users). Ignore +# > subtype_id (m2o mail.message.subtype). Look for relevant subtype if possible? + +# Fields in model mail.mail: +# > notification (bool) Is set to True in the model's create() method +# > mail_message_id (m2o, mail.message) DONE + === added file 'mail/migrations/7.0.1.0/post-migration.py' --- mail/migrations/7.0.1.0/post-migration.py 1970-01-01 00:00:00 +0000 +++ mail/migrations/7.0.1.0/post-migration.py 2013-07-23 18:20:38 +0000 @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 credativ Ltd (<http://credativ.co.uk>) +# (C) 2013 Therp BV (<http://therp.nl>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import logging +from openerp import pooler, SUPERUSER_ID +from openerp.tools.mail import html_sanitize, plaintext2html +from openerp.openupgrade import openupgrade + +logger = logging.getLogger('OpenUpgrade (mail)') + +subtype_mapping = { + 'plain': (openupgrade.get_legacy_name('body_text'), plaintext2html), + 'html': (openupgrade.get_legacy_name('body_html'), html_sanitize), + } + +def convert_mail_bodies(cr, pool): + """ + Convert plain and html bodies to sanitized html. + """ + message_obj = pool.get('mail.message') + for subtype in subtype_mapping.keys(): + field, func = subtype_mapping[subtype] + logger.info("converting %s messages", subtype) + cr.execute( + "SELECT id, %(field)s FROM mail_message " + "WHERE %(msg_subtype)s = '%(subtype)s'" % { + 'msg_subtype': openupgrade.get_legacy_name('subtype'), + 'field': field, + 'subtype': subtype, + }) + for row in cr.fetchall(): + body = func(row[1]) + cr.execute("UPDATE mail_message SET body = %s WHERE id = %s", body, row[0]) + +def create_mail_mail(cr, pool): + """ + Create mail.mail records for every mail.message in the system, + because every mail.message in 6.1 is a conventional email. + Also perform some other transformations. + """ + message_obj = pool.get('mail.message') + mail_obj = pool.get('mail.mail') + message_ids = message_obj.search([]) + messages = message_obj.read(message_obj.search([]), {}, '_classic_write') + + cr.execute("""SELECT user_id FROM mail_message""") + user_ids = dict(cr.fetchall) + + for message in messages: + # Set message type to notification + write_vals = { + 'type': 'notification', + } + # Convert user_id to author partner + if user_ids[message['id']]: + write_vals['author_id'] = openupgrade.get_partner_id_from_user_id( + cr, user_ids[message['id']]) + message_obj.write(message['id'], write_vals) + + # Set stored (but not recalculated) function field record_name + if message['model'] and message['res_id']: + model = pool.get(message['model']) + if model: + name = model.name_get( + cr, SUPERUSER_ID, [message['res_id']])[0][1] + cr.execute( + """ + UPDATE mail_message + SET record_name = %s + WHERE id = %s + """, name, message['id']) + + mail_id = mail_obj.create( + { + 'mail_message_id': message['id'], + }) + + # Copy legacy fields from message table to mail table + cr.execute( + """ + UPDATE mail_mail + SET mail.body_html = msg.body, + mail.mail_server_id = msg.%(mail_server_id)s, + mail.email_to = msg.%(email_to)s, + mail.email_cc = msg.%(email_cc)s, + mail.email_bcc = msg.%(email_bcc)s, + mail.reply_to = msg.%(reply_to)s, + mail.references = msg.%(references)s, + mail.state = msg.%(state)s, + mail.autodelete = msg.%(autodelete)s, + FROM mail_mail mail, mail_message msg + WHERE mail.mail_message_id = msg.id + """ % { + 'mail_server_id': openupgrade.get_legacy_name('mail_server_id'), + 'email_to': openupgrade.get_legacy_name('email_to'), + 'email_cc': openupgrade.get_legacy_name('email_cc'), + 'email_bcc': openupgrade.get_legacy_name('email_bcc'), + 'reply_to': openupgrade.get_legacy_name('reply_to'), + 'references': openupgrade.get_legacy_name('references'), + 'state': openupgrade.get_legacy_name('state'), + 'autodelete': openupgrade.get_legacy_name('autodelete'), + }) + + # Migrate m2o partner_id to m2m partner_ids + openupgrade.m2o_to_m2m( + cr, 'mail.message', 'mail_message', 'partner_ids', + openupgrade.get_legacy_name('partner_id')) + + [email protected]() +def migrate(cr, version): + pool = pooler.get_pool(cr.dbname) + convert_mail_bodies(cr, pool) + create_mail_mail(cr, pool) + openupgrade.load_data(cr, 'mail', 'migrations/7.0.1.0/data.xml') === added file 'mail/migrations/7.0.1.0/pre-migration.py' --- mail/migrations/7.0.1.0/pre-migration.py 1970-01-01 00:00:00 +0000 +++ mail/migrations/7.0.1.0/pre-migration.py 2013-07-23 18:20:38 +0000 @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (<http://therp.nl>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from openerp.openupgrade import openupgrade + +column_renames = { + 'mail.message': [ + # Existing fields to ignore + ('subtype', None), + ('headers', None), + ('display_text', None), + ('original', None), + # Existing fields to transform + ('body_text', None), + ('body_html', None), + ('partner_id', None), + ('user_id', None), + # Existing fields to move to mail.mail + ('email_to', None), + ('email_cc', None), + ('email_bcc', None), + ('reply_to', None), + ('references', None), + ('state', None), + ('autodelete', None), + ]} + [email protected]() +def migrate(cr, version): + openupgrade.rename_columns(cr, column_renames) + === added file 'mail/migrations/7.0.1.0/user_notes.txt' --- mail/migrations/7.0.1.0/user_notes.txt 1970-01-01 00:00:00 +0000 +++ mail/migrations/7.0.1.0/user_notes.txt 2013-07-23 18:20:38 +0000 @@ -0,0 +1,1 @@ +In OpenERP 7.0, regular emails and the new chatter functionality share a common base. Existing emails have been transformed on a technical level to fit to this new architecture.
-- Mailing list: https://launchpad.net/~credativ Post to : [email protected] Unsubscribe : https://launchpad.net/~credativ More help : https://help.launchpad.net/ListHelp

