Querying models

Inside a method or a shell session, self represents the current model, and we can only access that model's  records. To access other models, we should use self.env. For example, self.env['res.partner'] returns a reference to the Partners model (which is actually an empty recordset). We can then use search() or browse() on it to generate recordsets.

The search() method takes a domain expression and returns a recordset with the records matching those conditions. An empty domain [] will return all records.

If the model has the active special field, by default only the records with active=True will be considered.

A few optional keyword arguments are available, as shown here:

  • order is a string to be used as the ORDER BY clause ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.