[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.
This commit is contained in:
Toufik Benjaa
2018-08-22 17:59:22 +02:00
parent f750393030
commit 81f975d3f4
+2 -2
View File
@@ -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