Search code examples
xmlodooodoo-15

Odoo many2many checkboxes domain not working


I have these models

The model event.booth always has a halle_id The model order.wizard has an event_booth_id and event_booth_ids

Now, in the view form order.wizard in the many2many checkboxes widget from event_booth_ids I only want to show the records where the halle_id matches with the one from event_booth_id.halle_id

This is my current attempt (order wizard form):

<record id="rectanglemaps_create_order_view_form" model="ir.ui.view">
      <field name="name">rectanglemaps.order.wizard.form</field>
      <field name="model">rectanglemaps.order.wizard</field>
      <field name="arch" type="xml">
            <form>
                ...
                <field name="event_booth_ids" widget="many2many_checkboxes" domain="[('halle_id', '=', event_booth_id.halle_id)]"/>
            </form>
      </field>
</record>

As you can see i am trying to achieve this with the domain domain="[('halle_id', '=', self.event_booth_id.halle_id)]"

Unfortunately, I am getting the following error

Ungültiges zusammengesetztes Feld in domain="[('halle_id', '=', self.event_booth_id.halle_id)]"

Solution

  • As the error states: You can not use dottet fields in the second part of the domain. Instead you should create a related field like this:

    halle_id = self.Many2one(related='event_booth_id.halle_id')
    

    and use it in the domain like this:

    domain="[('halle_id', '=', halle_id)]"