Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
5818 Представления

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?

Аватар
Отменить
Автор Лучший ответ

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
    }
};
 
Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
февр. 21
3587
0
февр. 18
2827
5
дек. 17
5854
3
июн. 17
5632
0
янв. 16
3668