Manifest Academy

Home › Curriculum › Odoo Developer › Recordsets, CRUD, domains, env, context and sudo

The ORM · 20 min · 17–20

Recordsets, CRUD, domains, env, context and sudo

Working with recordsets, create/read/write/unlink, search and domains, the environment, context and privilege escalation.

In this lesson

Key points

Real-world example

A portal page showed every customer's invoices to whoever logged in. The controller used sudo().search([]) to 'fix' an AccessError. Replacing it with a search filtered on the current partner (and record rules doing their job without sudo) closed a serious data leak; the team added 'justify every sudo' to code review.

Questions and answers

How do you include archived records in a search?

with_context(active_test=False) (or add ('active','in',[True,False])).

What does env.ref('base.main_company') return?

The record with that external ID.

Read the full lesson, worked example and quiz