Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
18152 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează

Very excellent explanation (y)

Cel mai bun răspuns

sudo means run as superuser

Imagine profil
Abandonează