From 81f975d3f48239ee0722fb3892112db6915e7964 Mon Sep 17 00:00:00 2001 From: Toufik Benjaa Date: Wed, 22 Aug 2018 17:59:22 +0200 Subject: [PATCH] [FIX] mail: channel_get return wrong channel when duplicate partners - In some cases (merge of partners, etc ...) there might be mail.channel that have two mail.channel.partner with the same res.partner. When you try to open a discuss window with a partner for which you have no existing mail.channel. The channel opened is the one where your partner is duplicated. This is due to the fact that the SQL request to find the mail.channel doesn't take in account that a mail.channel may have twice the same partner. To fix this issue, we try to exactly match the partners we search. --- addons/mail/models/mail_channel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 91610463e81..372fc8ef0ea 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -361,8 +361,8 @@ class Channel(models.Model): AND P.partner_id IN %s AND channel_type LIKE 'chat' GROUP BY P.channel_id - HAVING COUNT(P.partner_id) = %s - """, (tuple(partners_to), len(partners_to),)) + HAVING array_agg(P.partner_id ORDER BY P.partner_id) = %s + """, (tuple(partners_to), sorted(list(partners_to)),)) result = self.env.cr.dictfetchall() if result: # get the existing channel between the given partners