This question has been flagged
4 Replies
7532 Views

Hello Guys


I got a weird Error when I try to create a record in my model. => Error, a partner cannot follow twice the same object.

Do you have any idea how to avoid this  ?

Thanks a lot

Avatar
Discard
Best Answer

you should delete the records from mail_followers.

eg:

delete from mail_followers where res_model in ('hr.attendance.status', 'hr_timesheet_sheet.sheet')

update the code with your concerned model. This is a limitation of the mail_followers model.

Avatar
Discard
Best Answer

Hi, you can use this code:

class Followers(models.Model):
_inherit = 'mail.followers'

@api.model
def create(self, vals):
if 'res_model' in vals and 'res_id' in vals and 'partner_id' in vals:
dups = self.env['mail.followers'].search([('res_model', '=',vals.get('res_model')),
('res_id', '=', vals.get('res_id')),
('partner_id', '=', vals.get('partner_id'))])
if len(dups):
for p in dups:
p.unlink()
res = super(Followers, self).create(vals)
return res
Avatar
Discard
Best Answer

Hi Othmane,

You can solve the issue by referring this blog, https://www.cybrosys.com/blog/how-to-get-rid-of-the-error-a-partner-cannot-follow-twice-the-same-object

Thanks

Avatar
Discard
Author Best Answer

I already see it, I want a general solution for all the models

Avatar
Discard