xmlfilteringodooformviewxmlformview

Filter by context/domain in Odoo 10


I have created a model Student with variables id, name, course. I need to display only students from courses x and y OR with names a and b in my xml form view. What I would do is add a context to the action associated to my form view like this:

<record id="action_view_student" model="ir.actions.act_window.view">
        <field name="view_mode">tree</field>
        <field name="view_id" ref="view_student" />
        <field name="act_window_id" ref="action_view_student" />
        <field name="domain">[('name', 'in', ['a','b']) **OR** ('course', 'in', ['x','y'])]</field>
     </record>

I am not sure how to set the OR in the domain.


Solution

  • It's well documented for example in the V11 Documentation

    The logical operators are prefixes and pay attention to the arity.

    Your example would be:

    ['|', ('name', 'in', ['a','b']), ('course', 'in', ['x','y'])]

    which reads name equals 'a' or 'b' OR course equals 'x' or 'y'

    Where

    ['|', ('name', 'in', ['a','b']), ('course', 'in', ['x','y']), ('active', '=', True)]

    reads (name equals 'a' or 'b' OR course equals 'x' or 'y') AND is active