Files
odoo_source/addons/hr/models/mail_channel.py
T
Gert PellinandRichard Mathot 76a557c9ac [IMP] hr,mail: auto-subscribe departments to channels
Purpose of this commit is to allow to make private channels linked to
an HR department with an auto subscription.

It will ease the use of discussion channels among employees of a given
department. Moreover auto subscription is useful to avoid having to
manually synchronize channel members and department members.

This commit is linked to task ID 1848526 and closes PR #26650 .

Co-authored-by: Gert Pellin <gpe@odoo.com>
Co-authored-by: Richard Mathot <rim@odoo.com>
2018-09-17 13:56:39 +02:00

28 lines
1.0 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(self):
""" Auto-subscribe members of a department to a channel """
super(Channel, self)._subscribe_users()
for mail_channel in self:
if mail_channel.subscription_department_ids:
mail_channel.write(
{'channel_partner_ids':
[(4, partner_id) for partner_id in mail_channel.mapped('subscription_department_ids.member_ids.user_id.partner_id').ids]})
def write(self, vals):
res = super(Channel, self).write(vals)
if vals.get('subscription_department_ids'):
self._subscribe_users()
return res