This question is asked often for tree views, but not for list view.
First some disambiguation:
- a tree view is a view with view_type = form and view_mode = tree
- a list view with view_type = tree
There a some very interessting differences between a list view and a tree view, e.g you can only use the parent-child-structure with list views, but that's not the topic.
For tree views, the solution is quite trivial. If the view_mode contains a form view, then a click on the tree view will automatically open the form view of the clicked record (though I don't know for sure if it's opened in the current or a new window). This is not the case for list views!
Anyway, for some more fancy actions triggered by clicking on a tree/list view, you will need to bind these actions with a ir.values record with key2 = tree_but_open.
When I try to open a form view of the clicked record in a list view it shows the form view, but for a new record. Not the clicked one.
Snippets:
<record id="open_project_from_hierarchy" model="ir.actions.act_window">
<field name="name">Project</field>
<field name="res_model">project.project</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_project"></field>
<field name="search_view_id" ref="view_project_filter"></field>
<field name="domain">[('id','=',active_id)]</field>
<field name="context">{}</field>
</record>
<record id="ir_open_project_form" model="ir.values">
<field name="key2" eval="'tree_but_open'"></field>
<field name="model" eval="'project.project'"></field>
<field name="name">View project</field>
<field name="value" eval="'ir.actions.act_window,'+str(open_project_from_hierarchy)"></field>
</record>
Note the domain on the bound action.
Any advise? Is it even possible to open the form view of the clicked record in a list view?
Thanks.
Open tree view in button click: https://learnopenerp.blogspot.com/2017/10/redirect-to-tree-view-from-button-click.html