odoo 10 javascript 小部件不工作:找不到客户端操作 'petstore.homepage'
odoo 10 javascript widget not working: Could not find client action 'petstore.homepage'
我从 github 中获取了 oepetstore 代码并对其进行了修改以适合 odoo10,但是它给我的错误是 Could not find client action 'petstore.homepage'
。在清单文件中,我包含了所有 xml 文件。 github 中提到的代码适用于 odoo9 但不适用于 10。
petstore.js,
odoo.define('oepetstore.petstore', function (require) {
"use strict";
var Class = require('web.Class');
var Widget = require('web.Widget');
var core = require('web.core');
var utils = require('web.utils');
var _t = core._t;
var _lt = core._lt;
var homePage = Widget.extend({
init: function(parent) {
this._super(parent);
console.log("Hello JS, I'm inside of init.");
},
start: function() {
console.log("Your pet store home page loaded");
},
});
core.view_registry.add('petstore', homePage);
});
petstore.xml,
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<template id="assets_backend" name="petstore_assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/oepetstore/static/src/css/petstore.css"/>
<script type="text/javascript" src="/oepetstore/static/src/js/petstore.js"/>
</xpath>
</template>
<menuitem id="main_petstore_menu" name="Pet Store" />
<menuitem id="petstore_menu" name="Pet Store"
parent="main_petstore_menu" />
<record id="action_home_page" model="ir.actions.client">
<field name="name">petstore</field>
<field name="tag">petstore</field>
</record>
<menuitem id="home_page_petstore_menu" name="Home Page" parent="petstore_menu"
action="action_home_page"/>
</data>
</odoo>
您正在 view_registry
上注册小部件
core.view_registry.add('petstore', homePage);
尝试添加到action_registry:
core.action_registry.add('petstore', homePage);
您可以在 XML 上看到您期待的是操作,而不是视图:
<record id="action_home_page" model="ir.actions.client">
在 xml
<record id="action_home_page" model="ir.actions.client">
<field name="name">Pet Store Home</field>
<field name="tag">petstore</field>
</record>
在 js 上而不是添加视图添加操作
core.action_registry.add('petstore', homePage);
还有odoo.define(module_name.js_file_name, .....)
我从 github 中获取了 oepetstore 代码并对其进行了修改以适合 odoo10,但是它给我的错误是 Could not find client action 'petstore.homepage'
。在清单文件中,我包含了所有 xml 文件。 github 中提到的代码适用于 odoo9 但不适用于 10。
petstore.js,
odoo.define('oepetstore.petstore', function (require) {
"use strict";
var Class = require('web.Class');
var Widget = require('web.Widget');
var core = require('web.core');
var utils = require('web.utils');
var _t = core._t;
var _lt = core._lt;
var homePage = Widget.extend({
init: function(parent) {
this._super(parent);
console.log("Hello JS, I'm inside of init.");
},
start: function() {
console.log("Your pet store home page loaded");
},
});
core.view_registry.add('petstore', homePage);
});
petstore.xml,
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<template id="assets_backend" name="petstore_assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/oepetstore/static/src/css/petstore.css"/>
<script type="text/javascript" src="/oepetstore/static/src/js/petstore.js"/>
</xpath>
</template>
<menuitem id="main_petstore_menu" name="Pet Store" />
<menuitem id="petstore_menu" name="Pet Store"
parent="main_petstore_menu" />
<record id="action_home_page" model="ir.actions.client">
<field name="name">petstore</field>
<field name="tag">petstore</field>
</record>
<menuitem id="home_page_petstore_menu" name="Home Page" parent="petstore_menu"
action="action_home_page"/>
</data>
</odoo>
您正在 view_registry
上注册小部件core.view_registry.add('petstore', homePage);
尝试添加到action_registry:
core.action_registry.add('petstore', homePage);
您可以在 XML 上看到您期待的是操作,而不是视图:
<record id="action_home_page" model="ir.actions.client">
在 xml
<record id="action_home_page" model="ir.actions.client">
<field name="name">Pet Store Home</field>
<field name="tag">petstore</field>
</record>
在 js 上而不是添加视图添加操作
core.action_registry.add('petstore', homePage);
还有odoo.define(module_name.js_file_name, .....)