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 of this commit is to better differentiate channel members technical
model from partner members in code :
* ``channel_partner_ids``: contacts member of a channel, filtering notably
on active and checking ACLs on res.partner business model. This one
should be used whenever we deal with members of a channel at business
level;
* ``channel_last_seen_partner_ids``: memberships of a channel and technical
model. This one should be used for internal processes and members
management;
Also containing
* clean naming or API of methods managing channel members. This should
not change anything functionally as only code renaming / cleaning is
performed;
* improve performances of channel member auto subscription by aggregating
all members to add and creating them at once;
* check the use of ``mail.channel.partner`` and ``res.partner`` records
through ``channel_last_seen_partner_ids`` and ``channel_partner_ids``
Channel fields;
Functionally nothing should change with this commit. It only cleans code
in order to prepare future modifications.
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
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models
|
|
|
|
|
|
class Channel(models.Model):
|
|
_inherit = 'mail.channel'
|
|
|
|
subscription_department_ids = fields.Many2many(
|
|
'hr.department', string='HR Departments',
|
|
help='Automatically subscribe members of those departments to the channel.')
|
|
|
|
def _subscribe_users_automatically_get_members(self):
|
|
""" Auto-subscribe members of a department to a channel """
|
|
new_members = super(Channel, self)._subscribe_users_automatically_get_members()
|
|
for channel in self:
|
|
new_members[channel.id] = list(
|
|
set(new_members[channel.id]) |
|
|
set((channel.subscription_department_ids.member_ids.user_id.partner_id - channel.channel_partner_ids).ids)
|
|
)
|
|
return new_members
|
|
|
|
def write(self, vals):
|
|
res = super(Channel, self).write(vals)
|
|
if vals.get('subscription_department_ids'):
|
|
self._subscribe_users_automatically()
|
|
return res
|