This question has been flagged
3 Replies
21129 Views

I want to CALL a specific TREE VIEW from JS, I have tried the following code, But is not working as expected


var model_obj = new instance.web.Model('ir.model.data');

var view_id = model_obj.call('get_object_reference',["MY MODULE NAME", "TREE VIEW ID"]);



var action = {
                                            type: 'ir.actions.act_window',
                                            res_model: 'crm.lead',
                                            view_mode: 'tree',
                                            view_type: 'tree',
                                            views:[[view_id, 'tree']],
                                            target: 'new',
                                            domain: [['state', '=', state]],
                                            context: context,
                                    };
                             
                                    action_manager = new ActionManager(self);
                                    action_manager.do_action(action);


1) The same works properly when the view_id is hard coded (Taken from ir.ui.view in DB)

2) I am not able to open this view in the current window but it works in new (Wizard) window that too after hard coding tree view ID else it brings the generic tree view for that model (In th wizard)

 

when I try to open the specific  tree view in the same window (ie) "target:current"this is what I get,


Uncaught TypeError: Cannot read property 'get_bus' of undefined

http://localhost:7000/web/content/743-605a4c6/web.assets_backend.js:3142 Traceback:
TypeError: Cannot read property 'get_bus' of undefined
    at Class.push_action (http://localhost:7000/web/content/743-605a4c6/web.assets_backend.js:3142:161)
    at http://localhost:7000/web/content/743-605a4c6/web.assets_backend.js:3175:170
    at http://localhost:7000/web/content/438-8117096/web.assets_common.js:650:681
    at fire (http://localhost:7000/web/content/438-8117096/web.assets_common.js:644:299)
    at Object.add [as done] (http://localhost:7000/web/content/438-8117096/web.assets_common.js:645:467)
    at Array.<anonymous> (http://localhost:7000/web/content/438-8117096/web.assets_common.js:650:649)
    at Function.each (http://localhost:7000/web/content/438-8117096/web.assets_common.js:473:767)
    at Object.<anonymous> (http://localhost:7000/web/content/438-8117096/web.assets_common.js:650:560)
    at Function.Deferred (http://localhost:7000/web/content/438-8117096/web.assets_common.js:651:194)
    at Object.then (http://localhost:7000/web/content/438-8117096/web.assets_common.js:650:525)


I want to open the specific tree view in the current window , If any one knows please share......

Avatar
Discard
Best Answer

Hi

i resume this post because i had the same problem.

I've solved with this code in javascript:

var model_obj = new instance.web.Model('ir.model.data');
var view_id = false;
model_obj.call('get_object_reference',['MODEL','VIEWNAME']).then( function(result){
    view_id = result[1];
});

this.do_action({
    views: [[view_id, 'form']],
....

i hope it can be helpful for others

Bye
Sandro

Avatar
Discard

Hi OnLabs Dev Team,

i tried your code but i got error: "Uncaught ReferenceError: instance is not defined". I don't know why and can u give me an answer? Thank ! :D

Best Answer

Hello brother! I have tried your solution but I'm getting this error: 

Uncaught TypeError: self._rpc is not a function

Avatar
Discard
Best Answer

This is the updated solution for version 14: 
Found these under the Odoo source code.

self._rpc({
    // Get view id
model:'ir.model.data',
method:'xmlid_to_res_model_res_id',
args: ['module_name.view_id'], // View id goes here
}).then(function(data){
    // Open view
    self.do_action({
    name: 'Example',
type: 'ir.actions.act_window',
res_model: 'your.module', // Module name goes here
target: 'new',
views: [[data[1], 'form']], // data[1] variable contains the view id
    });
});
Avatar
Discard