Obtaining an empty recordset for a different model
The current model’s methods are accessible through self
while creating Odoo code. It is not feasible to start working on a different model by simply instantiating its class; you must first obtain a recordset for that model.
This tutorial shows you how to get an empty recordset for any model that’s registered in Odoo inside a model method.
Getting ready
This tutorial will reuse the setup of the library example in the my_hostel
add-on module.
We will write a small method in the hostel.room
model and search for all hostel.room.members
. To do this, we need to get an empty recordset for hostel.room.members
. Make sure you have added the hostel.room.members
model and access rights for that model.
How to do it…
To get a recordset for hostel.room.members
in a method of hostel.room
, you need to perform the following steps:
Figure 5.1 – log_all_room_members
- In the...