跳至内容
菜单
此问题已终结

I'm following the Building Interface Extensions (https://www.odoo.com/documentation/11.0/howtos/web.html) with Odoo 11.

In the guide, it is stated that

"In Odoo web, modules are declared as functions set on the global odoo variable. The function's name must be the same as the addon (in this case oepetstore) so the framework can find it, and automatically initialize it."

But my module isn't being initialized and I get the following error:

"Action error - Could not find client action 'petstore.homepage'."



I put some logging in the module and I found that the file is being fetched by the browser, as expected, but the initialization isn't happening. 

This is my JS file:

odoo.oepetstore = function(instance, local) {
console.log('Started odoo.oepetstore'); ////////// [1] - This never runs

local.HomePage = instance.Widget.extend({
template: 'HomePageTemplate',
start: function() {
this.$el.append($('<div>').text('Hello dear Odoo user!'));
}
});
instance.web.client_actions.add('petstore.homepage', 'instance.oepetstore.HomePage');

}

console.log('Loaded petstore.js'); ////////// [2] - This always runs


With Odoo 9 (after renaming the file __manifest__.py to __openerp__.py and renaming the JS var odoo to openerp), everything works as expected.


Why isn't it working with Odoo 11? 

形象
丢弃
编写者 最佳答案

Unlike the guide, I had to define my module using odoo.require :


odoo.define('PetStoreHomePage', function(require){
    "use strict";

    var core = require('web.core');
    var Widget = require('web.Widget');

    var HomePageWidget = Widget.extend({
        template: 'HomePageTemplate',
        start: function() {
            this.$el.append($('<div>').text('Hello dear Odoo user!'));
        }
    });

    core.action_registry.add('petstore.homepage', HomePageWidget);
});
形象
丢弃

Yep, the documentation is outdated.

相关帖文 回复 查看 活动
2
10月 22
7745
1
5月 21
2906
2
5月 20
9501
1
1月 20
4735
0
8月 19
3703