What is the difference in search() and sudo.search() methods in odoo?
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 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
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