# Eagle Estates - Part 8
# To-Do's
- Create two new models,
eagle.property.roomandeagle.tag. - Create the following items for each of the new models except for the form view which will be only
for
eagle.property.room:- list view
- window action
- menu item
- model access right
- Add the following fields to the
eagle.propertymodel:- room_ids: a
One2manyfield witheagle.property.roomascomodel_nameandproperty_idasinverse_name - tag_ids: a
Many2manyfield witheagle.tagascomodel_name
- room_ids: a
- Add the following fields to the
eagle.property.roommodel:- room_type: a
Selectionfield with the following values: living, dining, kitchen, bedroom, bathroom, garage, other - area: a
Floatfield to store the area of the room in square meters - property_id: a
Many2onefield witheagle.propertyascomodel_name.
- room_type: a
# Notes
One2manyfields require aMany2onefield on the other model (comodel) that will act as the inverse field.Many2manyfield values are stored in a separate table, and therefore do not require an inverse field.
# Rooms:
# Model:
from odoo import models, fields
class EaglePropertyRoom(models.Model):
_name = 'eagle.property.room'
_description = 'Eagle Property Room'
room_type = fields.Selection([('bedroom', 'Bedroom'), ('bathroom', 'Bathroom'), ('dining', 'Dining Room'),
('living', 'Living Room'), ('garage', 'Garage'), ('kitchen', 'Kitchen'),
('other', 'Other')], default="other")
area = fields.Float()
property_id = fields.Many2one('eagle.property')
# Security:
access_eagle_property_room,access_eagle_property_room,model_eagle_property_room,,1,1,1,1
# Views:
<!-- Form View -->
<record id="view_eagle_property_room_form" model="ir.ui.view">
<field name="name">eagle.property.room.form</field>
<field name="model">eagle.property.room</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="room_type"/>
<field name="area"/>
<field name="property_id"/>
</group>
</sheet>
</form>
</field>
</record>
<!-- List View -->
<record id="view_eagle_property_room_list" model="ir.ui.view">
<field name="name">eagle.property.room.list</field>
<field name="model">eagle.property.room</field>
<field name="arch" type="xml">
<list>
<field name="room_type"/>
<field name="area"/>
<field name="property_id"/>
</list>
</field>
</record>
# Window Action:
<record id="eagle_property_rooms_action" model="ir.actions.act_window">
<field name="name">Rooms</field>
<field name="res_model">eagle.property.room</field>
<field name="view_mode">list,form</field>
</record>
# Menuitem:
<menuitem id="menu_eagle_property_rooms" name="Rooms" action="eagle_property_rooms_action" sequence="20"/>
# Tags:
# Model:
from odoo import models, fields
class EagleTag(models.Model):
_name = 'eagle.tag'
_description = 'Eagle Tag'
name = fields.Char(required=True)
# Security:
access_eagle_tag,access_eagle_tag,model_eagle_tag,,1,1,1,1
# Views:
<!-- List View -->
<record id="view_eagle_tag_list" model="ir.ui.view">
<field name="name">eagle.tag.list</field>
<field name="model">eagle.tag</field>
<field name="arch" type="xml">
<list editable="bottom">
<field name="name"/>
</list>
</field>
</record>
# Window Action:
<record id="eagle_tags_action" model="ir.actions.act_window">
<field name="name">Tags</field>
<field name="res_model">eagle.tag</field>
<field name="view_mode">list</field>
</record>
# Menuitem:
<menuitem id="menu_eagle_tags" name="Tags" action="eagle_tags_action" sequence="30"/>
# Properties:
# Model:
tag_ids = fields.Many2many('eagle.tag', string="Tags")
room_ids = fields.One2many('eagle.property.room', 'property_id', string="Rooms")
# Views:
<group>
<field name="tag_ids"/>
<field name="room_ids"/>
</group>
# Manifest:
'application': True