# Eagle Estates - Part 14
# To-Do's
- Add a computed integer field
room_countto theeagle.propertymodel. - The compute method should calculate the number of rooms from the length of
room_idsfield. - In the form view of
eagle.property, remove the existingroom_idsfield. - Add a smart button inside the
sheetelement and add the computed integer field as a stat and an appropriate fontawesome icon. - Add a Python method that returns an action to open the list view of the rooms.
- Add a button labeled Create Room inside the
headerelement of the form view. - Add a Python method that returns an action to open the form view of
eagle.property.room. - Disable creation of
eagle.property.roomrecords from its views by addingcreate="false"to thelistelement.
# Notes
- When viewing rooms, we should add a domain in the action to filter rooms by the current property.
- Similarly, when creating a new room, we should set a default value for the
property_idfield. This can be done by adding acontextkey to the action that opens the view.
# Properties
# Model:
room_count = fields.Integer(compute="_compute_room_count")
@api.depends("room_ids")
def _compute_room_count(self):
for record in self:
record.room_count = len(record.room_ids)
def action_view_rooms(self):
action = self.env.ref("eagle_estates.eagle_property_rooms_action").read()[0]
action["domain"] = [("property_id", "=", self.id)]
return action
def action_create_room(self):
action = self.env.ref("eagle_estates.eagle_property_rooms_action").read()[0]
action.update({
"context": {"default_property_id": self.id},
"views": [(False, "form")]
})
return action
# View:
<record id="view_eagle_property_form" model="ir.ui.view">
...
<field name="arch" type="xml">
<header>
<button name="action_create_room" string="Create Room" type="object"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button
class="oe_stat_button"
name="action_view_rooms"
type="object"
icon="fa-list"
invisible="not room_count"
>
<field string="Rooms" name="room_count" widget="statinfo"/>
</button>
</div>
...
</sheet>
</field>
</record>
# Rooms
# View:
<record id="view_eagle_property_room_list" model="ir.ui.view">
...
<field name="arch" type="xml">
<list create="false">
...
</list>
</field>
</record>