pythonxmlodooodoo-viewodoo-17

ODOO: Passing by default two filters in context using the AND operator


In the following action I am sending two filters and a grouping, the filters are search_default_projects_activities and search_default_active_poa, however, these filters are applied with the OR operator as can be seen in Image 1, I know I can configure in the GUI the condition (see Image 2) but I need that by default, or rather, by code it is indicated that the operator must be an AND. Any idea? Thanks in advance.

<record id="action_uc_planning_poa_dependency_project" model="ir.actions.act_window">
    <field name="name">Proyectos</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">uc_planning.poa_dependency_project</field>
    <field name="view_mode">tree,form</field>
    <field name="domain">[]</field>
    <field name="context">
        {
    ​   ​'search_default_poa_dependency_id': 1,
    ​   ​'search_default_active_poa':1,
    ​   ​'search_default_projects_activities': 1
        ​}
    </field>
</record>

Image 1

Filters with OR operator

Image 2

AND Operator

I tried to pass the two filters with an AND operator to the context by code, but I only achieved it by using the Odoo GUI. I need to set the filters with the AND operator using the views (XML) code.


Solution

  • Put a <separator/> between your two search filters.

    Like this:

    <filter string="My Tasks" name="my_tasks" domain="[('user_id','=',uid)]"/>
    
    <separator/>
    
    <filter string="Without Parent Tasks" name="without_parent_tasks" domain="[('parent_id','!=',False)]"/>
    

    Then set the Context area like this:

    `<field name="context">{'search_default_my_tasks': 1, 'search_default_without_parent_tasks': 1}</field>
    

    Now the two searches work like a charm with the AND operator.