From 8b854ab660309734856b07299cb5fc3e3550d2e6 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 28 Nov 2017 11:46:28 +0100 Subject: [PATCH] [FIX] mail: auto subscription to channel 1. Install mail and hr 2. Create a new mail channel: name: test Who can follow: selected group of user Authorized group: Employee / Manager Auto subscription: Employee / Manager 3. Edit the Demo user, and add him to group Employee Managers The Demo user is not subscribed to the channel (only Admin is) In this case, the web client sends a `sel_groups_` key, which is not handled by the `write` method. Fixes #20897 opw-782301 --- addons/mail/models/res_users.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/mail/models/res_users.py b/addons/mail/models/res_users.py index 19630150a75..6aa3e307876 100644 --- a/addons/mail/models/res_users.py +++ b/addons/mail/models/res_users.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import _, api, exceptions, fields, models +from odoo.addons.base.res.res_users import is_selection_groups class Users(models.Model): @@ -54,11 +55,14 @@ class Users(models.Model): @api.multi def write(self, vals): write_res = super(Users, self).write(vals) + sel_groups = [vals[k] for k in vals if is_selection_groups(k) and vals[k]] if vals.get('groups_id'): # form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]} user_group_ids = [command[1] for command in vals['groups_id'] if command[0] == 4] user_group_ids += [id for command in vals['groups_id'] if command[0] == 6 for id in command[2]] self.env['mail.channel'].search([('group_ids', 'in', user_group_ids)])._subscribe_users() + elif sel_groups: + self.env['mail.channel'].search([('group_ids', 'in', sel_groups)])._subscribe_users() return write_res def _create_welcome_message(self):