Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
6153 Vizualizări

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()
Imagine profil
Abandonează
Cel mai bun răspuns

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()
Imagine profil
Abandonează
Cel mai bun răspuns

Try this

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
mar. 23
2277
0
iun. 19
271
0
iul. 22
2132
0
iun. 17
5153
2
iun. 15
4509