Search code examples
odooodoo-17

How can I set Odoo 17's default grouping of a tree view by multiple fields?


Using the odoo's group, I need to configure my tree view to have a hierarchical view by default.

I created a group as follows

<group expand="0" string="Group By">
    <filter name="group_default" string="Default" domain="[]" context="{'group_by':['related_model_id', 'api_method']}"/>
</group>

and then configured it like this.

<field name="context">{"search_default_group_model":1} </field> 

but this is giving me error.

Any solutions?


Solution

  • You made a mistake by attempting to include more than one field in a single <filter> element's context. Instead, you should have added each field independently in separate <filter> tags as given below.

    <search>
       <group expand="0" string="Group By">
          <filter name="group_model" string="Model" domain="[]"
             context="{'group_by':'related_model_id'}"/>
          <filter name="group_method" string="Method" domain="[]"
             context="{'group_by':'api_method'}"/>
       </group>
    </search>
    

    And then you can just set multiple values for group by inside the action's context as follow.

    <field name="context">{
       "search_default_group_model":1,
       "search_default_group_method":1,
       }
    </field>
    

    This strategy will put the necessary functionality into place.