This question has been flagged
3 Replies
20116 Views

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.

Avatar
Discard
Best Answer

You can add the following to the tree view XML:

<button type="object" name="get_formview_action" string="Open" icon="fa-edit"/>
Avatar
Discard
Best Answer

René, I also need to open the form view by clicking the hierarchical tree view element. Did you find anything?


Avatar
Discard
Best Answer

openerp.your_module_name = function(instance) {

var QWeb = openerp.web.qweb;
_t = instance.web._t;

instance.web.TreeView.include({

activate: function(id) {
var self = this;
var result = self._super(id);

if (self.model == 'your.model'){

self.do_action({
type: 'ir.actions.act_window',
res_model: self.model,
view_type: 'form',
view_mode: 'form',
res_id: id,
views: [[false, 'form']],
});
}

return result;
},

});

Try to use this javascript

Avatar
Discard

I could'n make "activate" called on odoo14. It seems they have changes JS API.