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

47 Views Asked by At

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?

2

There are 2 best solutions below

2
Yassir Irfan On BEST ANSWER

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.

0
CZoellner On

Your filter is called group_default and odoo expects this name as second part in context right after search_default_. Following should be working:

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