Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
18190 Visualizzazioni

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

Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona

Very excellent explanation (y)

Risposta migliore

sudo means run as superuser

Avatar
Abbandona