Skip to Content
Menu
This question has been flagged
2 Replies
7130 Views

So I have been working with Odoo for 2 months, and this is the first time I encounter an issue when working with an ecommerce project. The solution coworker gave me was to use sudo() when searching. I read a similar question on this site and it said something about permission. My question is can I always use sudo, like sudo().search, if I need to use sudo to bypass permission, then is it a good idea to always use sudo because my code will always work?

Avatar
Discard
Best Answer

Hi  Trong,

Using sudo() will bypass all the Access and Record rule checks, If you are using sudo() in search it will return all the records without any restriction

If you are using a default search that is without sudo, the returned recordset contains the records with the login user's Access Rights and Record rules, If you don't have access to that model it throws Access Error

So be careful while using sudo(), As it Removes all the Access and Record rules and returns records without any restriction because returned recordset may contain records that the login user is not supposed to see.

Hope it helps,
Kiran K

Avatar
Discard
Best Answer

Hello Trong,

You have to use sudo() only when you have to perform the any operation with root user.

If you are using sudo() then it process that operation with root user so it doesn't need any permission.

Avatar
Discard