Skip to Content
Menu
This question has been flagged
4 Replies
7947 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
Author Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 24
1182
0
Feb 22
1120
0
Feb 20
1909
8
Jun 24
34839
1
Mar 23
1436