[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
This commit is contained in:
Thibault Delavallée
2021-03-17 18:07:01 +00:00
parent 0568a528fe
commit 74dc9795f5
5 changed files with 38 additions and 22 deletions
+2
View File
@@ -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
-18
View File
@@ -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
@@ -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'
)
""")
+9 -3
View File
@@ -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')
+4 -1
View File
@@ -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')