Obtaining an empty recordset for a different model
When writing Odoo code, the methods of the current model are available through 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 you how to get an empty recordset for any model that's registered in Odoo inside a model method.
Getting ready
This recipe will reuse the setup of the library example in the my_library
add-on module.
We will write a small method in the library.book
model and search for all library.members
. To do this, we need to get an empty recordset for library.members
. Make sure you have added the library.members
model and access rights for that model.
How to do it...
To get a recordset for library.members
in a method of library.book
, you need to perform the following steps:
- In the
LibraryBook
class, write a method calledget_all_library_members
...