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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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
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.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up