Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
18563 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć

Very excellent explanation (y)

Najlepsza odpowiedź

sudo means run as superuser

Awatar
Odrzuć