Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to open a form view from click on list view?

By
René Schuster
on 11/18/14, 9:37 AM 2,983 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.

0
Tony Green
On 12/24/15, 10:17 AM

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

0
Shahriar Siddik
On 5/1/15, 10:42 PM

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


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/18/14, 9:37 AM
Seen: 2983 times
Last updated: 2/4/16, 9:01 AM