Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
23410 Vistas

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
Descartar
Mejor respuesta

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
Descartar

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

Mejor respuesta

this worked for me in Odoo 17 =>

First the snippet from owl component (model in my case) that triggers the action to show the view

showView() {

​self = this.action; // has to be set in constructor

        self.rpc("/web/action/load", 

​{ action_id: "my_module.my_action_id" })            

​.then(function (result) {                

​const treeView = result.views.find((v) => v[1] === "list");

                ​// Open view   with owl action service

             ​self.action.doAction({                    

​name: 'Standards des Partners',                    

​type: 'ir.actions.act_window',                    

​res_model: 'my_module.my_model', 

​                  target: 'new',                    

​domain: domain,                    

​views: [[treeView[0], 'tree']], view id                

​});            

​}).catch(function (error) { 

​console.log(error);                

​throw error;           

​ });

Second the initialization of services used:

const myDashBoardService = {    

​dependencies: ["action", "effect", "notification", "orm", "rpc"],

    ​start(env, services) {        

​const dashboardModel = new myDashboardModel(

​services["orm"], services["rpc"], services["action"]

​);

        return dashboardModel;    }

};


registry.category("services").add("my_dashboard.service", myDashBoardService);

Avatar
Descartar
Mejor respuesta

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

Uncaught TypeError: self._rpc is not a function

Avatar
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
sept 23
1270
0
sept 23
1074
2
feb 23
10242
6
oct 23
20877
3
mar 24
8614