Home > OS >  Odoo many2many checkboxes domain not working
Odoo many2many checkboxes domain not working

Time:10-05

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)]"

CodePudding user response:

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)]"

CodePudding user response:

You can't use dotted field names in domain and by default, self is not available in the evaluation context

You can use a related field:

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

And use it in domain like following:

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

The halle_id field must be present in wizard form

  • Related