From 136fee6fcf976cc7b23a699732b832d643473fdd Mon Sep 17 00:00:00 2001 From: XavierDo Date: Mon, 19 Nov 2018 10:21:36 +0000 Subject: [PATCH] [FIX] mail_bot: only display odoobot once in mention suggestions Before this commit odoobot was appearing twice in mention suggestions when talking to odoobot. The initial need to be able to ping odoobot from everywhere led to the override of channel_fetch_listeners. This is not usefull anymore. This fix simply removes this override to avoid this problem since we don't have a real use case where we need to ping odoobot in another channel. Task 1907142 closes odoo/odoo#28791 --- addons/mail_bot/models/mail_channel.py | 7 ------- addons/test_mail/tests/test_odoobot.py | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/mail_bot/models/mail_channel.py b/addons/mail_bot/models/mail_channel.py index 3e2258902bf..efada26b88a 100644 --- a/addons/mail_bot/models/mail_channel.py +++ b/addons/mail_bot/models/mail_channel.py @@ -11,13 +11,6 @@ class Channel(models.Model): super(Channel, self)._execute_command_help(**kwargs) self.env['mail.bot']._apply_logic(self, kwargs, command="help") # kwargs are not usefull but... - @api.model - def channel_fetch_listeners(self, uuid): - """ Return the id, name and email of partners listening to the given channel """ - result = super().channel_fetch_listeners(uuid) - odoobot = self.env.ref("base.partner_root").sudo() - return result + [{'id': odoobot.id, 'name': odoobot.name, 'email': odoobot.email}] - @api.model def init_odoobot(self): if self.env.user.odoobot_state == 'not_initialized': diff --git a/addons/test_mail/tests/test_odoobot.py b/addons/test_mail/tests/test_odoobot.py index 50170f91604..07cdfaa0d3a 100644 --- a/addons/test_mail/tests/test_odoobot.py +++ b/addons/test_mail/tests/test_odoobot.py @@ -24,6 +24,14 @@ class TestOdoobot(BaseFunctionalTest, MockEmails, TestRecipients): self.odoobot_ping_body = '@OdooBot' % (self.odoobot.id, self.odoobot.id) self.test_record_employe = self.test_record.sudo(self.user_employee) + @mute_logger('odoo.addons.mail.models.mail_mail') + def test_fetch_listener(self): + channel = self.env['mail.channel'].sudo(self.user_employee).init_odoobot() + partners = self.env['mail.channel'].channel_fetch_listeners(channel.uuid) + odoobot = self.env.ref("base.partner_root") + odoobot_in_fetch_listeners = [partner for partner in partners if partner['id'] == odoobot.id] + self.assertEqual(len(odoobot_in_fetch_listeners), 1, 'odoobot should appear only once in channel_fetch_listeners') + @mute_logger('odoo.addons.mail.models.mail_mail') def test_odoobot_ping(self): kwargs = self.message_post_default_kwargs.copy()