Odoo 11 Web JS Framework 没有初始化我的模块,因此没有注册我的客户端操作

Odoo 11 Web JS Framework doesn't initialize my module and thus doesn't register my client action

我正在使用 Odoo 11 关注 Building Interface Extensions guide

指南中指出

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.

但是我的模块没有被初始化,我收到以下错误:

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

我在模块中放置了一些日志记录,我发现浏览器正在按预期获取文件,但没有进行初始化。

这是我的 JS 文件:

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

使用 Odoo 9(将文件 __manifest__.py 重命名为 __openerp__.py 并将变量 odoo 重命名为 openerp 后,一切都按预期工作。

为什么它不能与 Odoo 11 一起使用?


编辑

这是我遵循 :

后的工作代码

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);
});

在新版本的 odoo 中,当你定义一个 javascript 模块时使用这个:

              // key of your module so other require it.
  odoo.define('your_module_name.name_to_discript_functionality', function(require) {
    'use strict'
     // user require to load module that your module depends on them
     var web = require('web.code');
     // if someone need your module function he will load it by it's key 
     // var YouModule = require('your_module_name.name_to_discript_functionality');



    // if you define new class return them so other can use them
    return {
        NewClass : NewClass,
        ...
        ...
    }

  });