Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
6186 มุมมอง

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()
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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()
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Try this

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 23
2285
0
มิ.ย. 19
271
0
ก.ค. 22
2157
0
มิ.ย. 17
5166
2
มิ.ย. 15
4537