This question has been flagged

I have a server action that is removing/unlinking certain followers from an opportunity. Since Administrator(s) is the only ones allowed to unlink a follower, my users can't save. How can I have the automated server action run as if it is the administrator even though the user is actually the one running it?

# Available variables:
# - time, datetime, dateutil, timezone: Python libraries
# - env: Odoo Environement
# - model: Model of the record on which the action is triggered
# - record: Record on which the action is triggered if there is one, otherwise None
# - records: Records on which the action is triggered if there is one, otherwise None
# - log : log(message), function to log debug information in logging table
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {...}

if env['crm.lead'].search([('id','=',record.id),('type','!=','lead')]):
env['mail.followers'].search([('res_id','=',record.id),('res_model','=','crm.lead'),('partner_id.name','like','<')]).unlink()
Avatar
Discard
Best Answer

Hi Risser, 

to run it as a superadmin, simply add sudo() like this : 

env['mail.followers'].search([('res_id','=',record.id),('res_model','=','crm.lead'),('partner_id.name','like','<')]).sudo().unlink()
Avatar
Discard
Best Answer

Try this

env['mail.followers'].search([('res_id','=',record.id),('res_model','=','crm.lead'),('partner_id.name','like','<')]).sudo().unlink()

Avatar
Discard