跳至内容
菜单
此问题已终结
2 回复
18618 查看

What is the difference in search() and sudo.search() methods in odoo?

形象
丢弃
最佳答案

Hi Ogulgerek,

If you do a default search you're doing it with the user rights and privileges of the current user that executes this command/action. For example: if you do not have rights to the model "account.invoice" and in your code you do self.env['account.invoice'].search([]) it will give back a security warning. If you'd like to bypass this you can use sudo(). If you use sudo() Odoo will run your command as if it is run by an user with full rights on everything (administrator user up until V12 and OdooBot for V12/V13). You have to be careful when you use sudo() though as it removes all security checks. As a general rule of thumb you shouldn't use sudo unless you're really sure that you want to have all records without any restrictions. With great power comes great responsibility I guess ;-)

You can see how it works in code at https://github.com/odoo/odoo/blob/f71979a681d95d98db19a80feb59fdf684ec361f/odoo/models.py#L4990-L5020 to really understand what it does.

Regards,

Yenthe

形象
丢弃

Very excellent explanation (y)

最佳答案

sudo means run as superuser

形象
丢弃