From 62829ac36443a7383a5875e85808307331fbd99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 4 Nov 2015 12:04:56 +0100 Subject: [PATCH] [FIX] mail: avoid duplicate entries in model mail.channel.partner in some cases, it is possible to call the method channel_join_and_getinfo when the user is already in the channel. This may (and did) cause issues in some unrelated code. This commit guarantees that this codepath will avoir creating another entry. Another way to achieve this result is by adding a constraint on the model mail.channel.partner, but this is in 9.0, so we must be careful. --- addons/mail/models/mail_channel.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index e569bd8e56f..daac4829235 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -142,7 +142,10 @@ class Channel(models.Model): @api.multi def action_follow(self): - return self.write({'channel_last_seen_partner_ids': [(0, 0, {'partner_id': self.env.user.partner_id.id})]}) + self.ensure_one() + channel_partner = self.mapped('channel_last_seen_partner_ids').filtered(lambda cp: cp.partner_id == self.env.user.partner_id) + if not channel_partner: + return self.write({'channel_last_seen_partner_ids': [(0, 0, {'partner_id': self.env.user.partner_id.id})]}) @api.multi def action_unfollow(self):