From 5b20117495b908bde3877c02db3ada7249eb7993 Mon Sep 17 00:00:00 2001 From: dmonzonis Date: Fri, 8 May 2020 10:06:13 +0000 Subject: [PATCH] [FIX] mail: channel_get not finding channels correctly The channel_get method from mail.channel was not retrieving existing channels between partners correctly in some cases, which caused some annoyances, like OdooBot creating a new channel/thread each time the admin user logs in to remind them about changing the default password, instead of using an existing conversation. This was caused because because the SQL query was filtering the channels by comparing the partner ids to the result of the ARRAY_AGG function, which sometimes contains duplicates. Task ID: 2233014 PR #49661 --- addons/mail/models/mail_channel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 5d9d988d9dc..b6e11e4fdc3 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -633,14 +633,14 @@ class Channel(models.Model): partners_to.append(self.env.user.partner_id.id) # determine type according to the number of partner in the channel self.env.cr.execute(""" - SELECT P.channel_id as channel_id + SELECT P.channel_id FROM mail_channel C, mail_channel_partner P WHERE P.channel_id = C.id AND C.public LIKE 'private' AND P.partner_id IN %s - AND channel_type LIKE 'chat' + AND C.channel_type LIKE 'chat' GROUP BY P.channel_id - HAVING array_agg(P.partner_id ORDER BY P.partner_id) = %s + HAVING ARRAY_AGG(DISTINCT P.partner_id ORDER BY P.partner_id) = %s """, (tuple(partners_to), sorted(list(partners_to)),)) result = self.env.cr.dictfetchall() if result: