Obtaining an empty recordset for a different model

When writing Odoo code, the methods of the current model are available via self. If you need to work on a different model, it is not possible to directly instantiate the class of that model—you need to get a recordset for that model to start working.

This recipe shows how to get an empty recordset for any model registered in Odoo inside a model method.

Getting ready

This recipe will reuse the setup of the library example in the addon module my_module.

We will write a small method in the library.book model searching for all library.members. To do this, we need to get an empty recordset for library.members.

How to do it…

To get a recordset for library.members in a method of library.book, you need to take ...

Get Odoo Development Cookbook 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.