Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet

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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

Try this

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

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
März 23
2279
0
Juni 19
271
0
Juli 22
2134
0
Juni 17
5155
2
Juni 15
4512