Select related field before the field itself - Odoo 8

122 Views Asked by At

I'm working on Odoo 8 and i have 3 tables : bloc, floor and room

with floor having a many2one relation with bloc, and room having a many2one relation with floor

when creating a room record, i want to select the bloc first so i can load floors in that bloc only, but without having a many2one relation between room and bloc, since it'd be redundant

is there a way to do that?

i tried to look for a way to group the floors by bloc in the selection but even that couldn't work.

1

There are 1 best solutions below

3
Kenly On

You can use a related field and use it in the floor field domain to filter out blocs.

Related fields are not stored by default, they are computed and returned when requested (Odoo will not create a database column in the room table)

Example:

  • Room model

    class Room(models.Model):
        _name = 'room.room'
    
        floor_id = fields.Many2one('floor.floor')
        bloc_id = fields.Many2one(related="floor_id.bloc_id")
    
  • Form view

    <field name="floor_id" domain="[('bloc_id', '=', bloc_id)]"/>