Skip to content

Commit

Permalink
[MIG] im_livechat
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Oct 28, 2020
1 parent ab91294 commit 80dd5b3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---Models in module 'im_livechat'---
---Fields in module 'im_livechat'---
im_livechat / im_livechat.channel / image (binary) : DEL attachment: True
im_livechat / im_livechat.channel / image_128 (binary) : NEW attachment: True, hasdefault
im_livechat / im_livechat.channel / image_medium (binary) : DEL attachment: True
im_livechat / im_livechat.channel / image_small (binary) : DEL attachment: True
# DONE: pre-migration: handled image rename

im_livechat / im_livechat.channel / rating_ids (one2many) : NEW relation: rating.rating
im_livechat / mail.channel / country_id (many2one) : NEW relation: res.country
im_livechat / res.users / livechat_username (char) : NEW
# NOTHING TO DO (tentative)

im_livechat / mail.channel / livechat_operator_id (many2one): NEW relation: res.partner
# DONE: pre-migration: filled with the user_ids of im_livechat.channel

---XML records in module 'im_livechat'---
NEW im_livechat.channel: im_livechat.im_livechat_channel_data
# DONE: pre-migration: renamed xmlid from website_livechat.im_livechat_channel_data_website is website_livechat is installed

NEW ir.rule: im_livechat.im_livechat_rule_manager_read_all_mail_channel
NEW ir.ui.view: im_livechat.im_livechat_channel_view_search
NEW ir.ui.view: im_livechat.livechat_email_template (noupdate)
NEW ir.ui.view: im_livechat.res_users_form_view
NEW ir.ui.view: im_livechat.res_users_form_view_simple_modif
# NOTHING TO DO
51 changes: 51 additions & 0 deletions addons/im_livechat/migrations/13.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2020 ForgeFlow <http://www.forgeflow.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade


_field_renames = [
('im_livechat.channel', 'im_livechat_channel',
'image_medium', 'image_128'),
]


def rename_image_attachments(env):
for old, new in [("image_medium", "image_128")]:
openupgrade.logged_query(
env.cr, """
UPDATE ir_attachment SET res_field = %s
WHERE res_field = %s AND res_model = 'im_livechat.channel'""",
(new, old),
)


def fill_mail_channel_livechat_operator_id(env):
# Done in pre-migration to avoid sql constraint
openupgrade.logged_query(
env.cr, """
ALTER TABLE mail_channel
ADD COLUMN livechat_operator_id integer""",
)
openupgrade.logged_query(
env.cr, """
UPDATE mail_channel mc
SET livechat_operator_id = ru.partner_id
FROM im_livechat_channel ilc
JOIN im_livechat_channel_im_user ilciu ON ilciu.channel_id = ilc.id
JOIN res_users ru ON ru.id = ilciu.user_id
WHERE mc.livechat_channel_id = ilc.id
AND mc.livechat_operator_id IS NULL"""
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(env, _field_renames)
if openupgrade.column_exists(
env.cr, "im_livechat_channel", "website_description"):
openupgrade.rename_xmlids(env.cr, [
("website_livechat.im_livechat_channel_data_website",
"im_livechat.im_livechat_channel_data"),
])
rename_image_attachments(env)
fill_mail_channel_livechat_operator_id(env)
2 changes: 1 addition & 1 deletion odoo/openupgrade/doc/source/modules120-130.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ missing in the new release are marked with |del|.
+----------------------------------------------+-------------------------------------------------+
|iap | Done |
+----------------------------------------------+-------------------------------------------------+
|im_livechat | |
|im_livechat | Done |
+----------------------------------------------+-------------------------------------------------+
|im_livechat_mail_bot | |
+----------------------------------------------+-------------------------------------------------+
Expand Down

0 comments on commit 80dd5b3

Please sign in to comment.