From 74dc9795f5b9c1712bb171e8ca2e965acd832165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 19 Feb 2021 11:25:55 +0000 Subject: [PATCH] [MOV] mail, im_livechat: split models related to mail channel and reorder some fields definitions RATIONALE Channel model is a mail.thread enabled model behaving strangely with followers, notifications and discuss. Its code should however be simplified to be more self contained and avoid unwanted side effects on other models. SPECIFICATIONS Purpose is to prepare modifications in models by doing a preparatory cleaning of some fields and model definitions. Notably * move mail.channel.partner im_livechat override in its own file; * slightly re-order member-related fields on channel or mail.channel.partner models, and split long lines; This commit should not change anything functionally as it contains is only some code move and reordering. LINKS Task ID-2070632 (main task) Task ID-2419762 (followup task) COM PR odoo/odoo#62859 ENT PR odoo/enterprise#15172 UPG PR odoo/upgrade#2005 --- addons/im_livechat/models/__init__.py | 2 ++ addons/im_livechat/models/mail_channel.py | 18 --------------- .../models/mail_channel_partner.py | 23 +++++++++++++++++++ addons/mail/models/mail_channel.py | 12 +++++++--- addons/mail/models/mail_channel_partner.py | 5 +++- 5 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 addons/im_livechat/models/mail_channel_partner.py diff --git a/addons/im_livechat/models/__init__.py b/addons/im_livechat/models/__init__.py index bc392a29c43..a22a22519cb 100644 --- a/addons/im_livechat/models/__init__.py +++ b/addons/im_livechat/models/__init__.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -* + from . import res_users from . import res_partner from . import im_livechat_channel from . import mail_channel +from . import mail_channel_partner from . import rating from . import digest diff --git a/addons/im_livechat/models/mail_channel.py b/addons/im_livechat/models/mail_channel.py index 4f716758bbc..720421533cf 100644 --- a/addons/im_livechat/models/mail_channel.py +++ b/addons/im_livechat/models/mail_channel.py @@ -3,24 +3,6 @@ from odoo import api, fields, models, _ -class ChannelPartner(models.Model): - _inherit = 'mail.channel.partner' - - @api.autovacuum - def _gc_unpin_livechat_sessions(self): - """ Unpin livechat sessions with no activity for at least one day to - clean the operator's interface """ - self.env.cr.execute(""" - UPDATE mail_channel_partner - SET is_pinned = false - WHERE id in ( - SELECT cp.id FROM mail_channel_partner cp - INNER JOIN mail_channel c on c.id = cp.channel_id - WHERE c.channel_type = 'livechat' AND cp.is_pinned is true AND - cp.write_date < current_timestamp - interval '1 day' - ) - """) - class MailChannel(models.Model): """ Chat Session diff --git a/addons/im_livechat/models/mail_channel_partner.py b/addons/im_livechat/models/mail_channel_partner.py new file mode 100644 index 00000000000..f1a2369fb00 --- /dev/null +++ b/addons/im_livechat/models/mail_channel_partner.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class ChannelPartner(models.Model): + _inherit = 'mail.channel.partner' + + @api.autovacuum + def _gc_unpin_livechat_sessions(self): + """ Unpin livechat sessions with no activity for at least one day to + clean the operator's interface """ + self.env.cr.execute(""" + UPDATE mail_channel_partner + SET is_pinned = false + WHERE id in ( + SELECT cp.id FROM mail_channel_partner cp + INNER JOIN mail_channel c on c.id = cp.channel_id + WHERE c.channel_type = 'livechat' AND cp.is_pinned is true AND + cp.write_date < current_timestamp - interval '1 day' + ) + """) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 0f2e80f47eb..b7c692c2d4b 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -49,9 +49,15 @@ class Channel(models.Model): email_send = fields.Boolean('Send messages by email', default=False) image_128 = fields.Image("Image", max_width=128, max_height=128, default=_get_default_image) # members (depends=['...'] is for `test_mail/tests/common.py`, class Moderation, `setUpClass`) - channel_last_seen_partner_ids = fields.One2many('mail.channel.partner', 'channel_id', string='Last Seen', depends=['channel_partner_ids']) - channel_partner_ids = fields.Many2many('res.partner', 'mail_channel_partner', 'channel_id', 'partner_id', string='Listeners', depends=['channel_last_seen_partner_ids']) - channel_message_ids = fields.Many2many('mail.message', 'mail_message_mail_channel_rel') + channel_partner_ids = fields.Many2many( + 'res.partner', 'mail_channel_partner', 'channel_id', 'partner_id', + string='Listeners', depends=['channel_last_seen_partner_ids']) + channel_last_seen_partner_ids = fields.One2many( + 'mail.channel.partner', 'channel_id', string='Last Seen', + depends=['channel_partner_ids']) + channel_message_ids = fields.Many2many( + 'mail.message', 'mail_message_mail_channel_rel', + string='Channel Messages') is_member = fields.Boolean('Is a member', compute='_compute_is_member') is_subscribed = fields.Boolean( 'Is Subscribed', compute='_compute_is_subscribed') diff --git a/addons/mail/models/mail_channel_partner.py b/addons/mail/models/mail_channel_partner.py index 426c6eba94b..27bf14cf7fc 100644 --- a/addons/mail/models/mail_channel_partner.py +++ b/addons/mail/models/mail_channel_partner.py @@ -11,10 +11,13 @@ class ChannelPartner(models.Model): _table = 'mail_channel_partner' _rec_name = 'partner_id' - custom_channel_name = fields.Char('Custom channel name') + # identity partner_id = fields.Many2one('res.partner', string='Recipient', ondelete='cascade', required=True) partner_email = fields.Char('Email', related='partner_id.email', readonly=False) + # channel channel_id = fields.Many2one('mail.channel', string='Channel', ondelete='cascade', required=True) + # state + custom_channel_name = fields.Char('Custom channel name') fetched_message_id = fields.Many2one('mail.message', string='Last Fetched') seen_message_id = fields.Many2one('mail.message', string='Last Seen') fold_state = fields.Selection([('open', 'Open'), ('folded', 'Folded'), ('closed', 'Closed')], string='Conversation Fold State', default='open')