TypeError: instance.web.core is undefined

TypeError: instance.web.core is undefined

我无法在 Odoo9 中添加新操作

openerp.pr_finance = function(instance, local) {
    var _t = instance.web._t, _lt = instance.web._lt;
    var QWeb = instance.web.qweb;
    var Widget = instance.web.Widget;
    var core = instance.web.core;
    var data = instance.web.data;
    var session = instance.web.session;
    var utils = instance.web.utils;
    var Model = instance.web.Model;
    var ControlPanelMixin = instance.web.ControlPanelMixin;     
    instance.web.ListView.include({
        init: function() {
            //console.log('JS loaded');
            this._super.apply(this, arguments);
        },
        render_buttons: function(data) {
            console.log('JS loaded load_list');
            console.log(data);
            this._super(data);
            if (this.$buttons) {
                this.$buttons.find('.oe_my_button').click(this.proxy('do_import_file_csv_ya_tz')) ;
            }
        },
        do_import_file_csv_ya_tz: function () {
            console.log('123123123123123123 ooops....');
            this.do_action(
                {
                    name: _t("IMPORT MY FILE"),
                    type: "ir.actions.client",
                    tag: 'import_csv',
                    params: {}
                }
            );
        }
    });

    var import_csv_yandex = Widget.extend({
        template: 'ImportViewYaTC',
        start: function () {    
            console.log("ImportViewYandexTC page loaded");         
        },
    });

    var DataImport = Widget.extend(ControlPanelMixin, {
        template: 'ImportView',
        init: function(parent, action) {
            console.log("init ImportView");
            this._super.apply(this, arguments);
            action.display_name = _t('Import a File');
        },
        start: function () {
            console.log("ImportView page loaded");
        },
    });
    console.log("core.action_registry.add");
    try {
        instance.web.core.action_registry.add('import_csv', DataImport);
    } catch (err) {
        console.log(err);

    }
    console.log("core.action_registry.add - OK!");
}

我在这里收到错误:

instance.web.core.action_registry.add('import_csv', DataImport);

错误:

TypeError: instance.web.core is undefined Stack trace: openerp.pr_finance@http//localhost:8069/web/content/2798-e13ba1c/web.assets_backend.js:4579:1276 start_modules@http//localhost:8069/web/content/2798-e13ba1c/web.assets_backend.js:3235:1 .init@http//localhost:8069/web/content/2798-e13ba1c/web.assets_backend.js:3229:3951 OdooClass.extend/Class.include/

为什么这个变量未定义?

您需要使用require获取环境的变量:ie.

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

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

了解 odoo 中的继承的一个好地方是 github.com/oca/web 存储库。