Skip to Content
Menu
This question has been flagged

I need to run some client-side javascript from a button in a form view in Odoo 8. This button runs a python method which returns this dictionary:

{"type": "ir.actions.client",
 "tag": "my_module.do_something",}

do_something is defined in a .js file as follows:

openerp.my_module = function (instance) {
    instance.web.client_actions.add("my_module.do_something", "instance.my_module.Action");
    instance.my_module.Action = instance.web.Widget.extend({
        init: function() {
            // Do a lot of nice things here
        }
    });
};

Now, the javascript is loaded and executed properly, but even before launching the init function, Odoo loads a brand new, blank view, and once the javascript is over I can't get browse any other menu entry. In fact, wherever I click I get this error:

Uncaught TypeError: Cannot read property 'callbackList' of undefined

What I need instead is to run the javascript from the form view where the button belongs, without loading a new view, so both getting the javascript stuff done and leaving all callbacks and the whole environment in a good state. My gut feeling is that I shouldn't override the init funcion (or maybe the whole thing is broken, I'm quite new to Odoo client-side js) , but I couldn't find docs neither a good example to call js the way I want. Any idea to get that?

Avatar
Discard
Author Best Answer

I found a way to fix my issue by rewriting the js function:

openerp.my_module = function (instance) {
    instance.web.client_actions.add("my_module.do_something", "instance.my_module.action");
    instance.my_module.action = function (parent, action) {
        // Do a lot of nice things here
    }
};
 
Avatar
Discard
Related Posts Replies Views Activity
0
Feb 21
2446
0
Feb 18
1976
5
Dec 17
4743
3
Jun 17
4403
0
Jan 16
2655