In Odoo16: How to get different context (group_by...) for different views (form, tree...). I would like for the standard model related "ir.actions.act_window", a context for the view_mode=gantt and another one for the view_mode=kanban... corresponding to the icon under the standard control panel... it could look like something like:
<record model="ir.actions.act_window" id="action_event_view">
<field name="name">Events</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">event.event</field>
<field name="view_mode">kanban, gantt</field>
<field name="context" FOR-VIEW="GANTT">{"search_default_upcoming":1}</field>
<field name="context" FOR-VIEW="KANBAN">{'group_by':'date_begin'}</field>
</record>
... writing it as python expression does not work neither:
<record model="ir.actions.act_window" id="action_event_view">
<field name="name">Events</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">event.event</field>
<field name="view_mode">kanban, gantt</field>
<field name="context">
{
if view_mode=="gantt":
"'search_default_upcoming':1"
elif view_mode=="kanban":
"'group_by':'date_begin'"
}
</field>
</record>
Or, is there any way to use multiple "ir. actions.act_window.view" for the views icons listed under the search panel ? something similar to:
<record id="action_custom_event_gantt_view" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">gantt</field>
<field name="view_id" ref="view_event_gantt"/>
<field name="context">{"search_default_upcoming":1}</field>
<field name="act_window_id" ref="action_event_view"/>
</record>
<record id="action_custom_event_kanban_view" model="ir.actions.act_window.view">
<field name="sequence" eval="1"/>
<field name="view_mode">kanban</field>
<field name="view_id" ref="view_event_kanban"/>
<field name="context">{'group_by':'date_begin'}</field>
<field name="act_window_id" ref="action_event_view"/>
</record>
You can use default_group_by
on the view defintion.
<gantt js_class="hr_gantt" color="employee_id" date_start="date_close" date_stop="date_close" default_group_by="department_id">