Skip to content

Commit

Permalink
[FIX] mail_bot: only display odoobot once in mention suggestions.
Browse files Browse the repository at this point in the history
The initial need to be able to ping odoobot from everywhere led to the
overwrite of channel_fetch_listeners. The odoobot will appear twice
in mention suggestion in a channel with odoobot. This fix simply remove
this overwrite to avoid this problem.
  • Loading branch information
Xavier-Do committed Nov 19, 2018
1 parent 99a7b44 commit 9a66a86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 0 additions & 7 deletions addons/mail_bot/models/mail_channel.py
Expand Up @@ -11,13 +11,6 @@ def _execute_command_help(self, **kwargs):
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':
Expand Down
8 changes: 8 additions & 0 deletions addons/test_mail/tests/test_odoobot.py
Expand Up @@ -24,6 +24,14 @@ def setUp(self):
self.odoobot_ping_body = '<a href="http://odoo.com/web#model=res.partner&amp;id=%s" class="o_mail_redirect" data-oe-id="%s" data-oe-model="res.partner" target="_blank">@OdooBot</a>' % (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 testfetch_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()
Expand Down

0 comments on commit 9a66a86

Please sign in to comment.