我还在学习如何正确添加您自己的 javascript 代码。我正在尝试将自己的东西添加到Odoo后端。任何人都可以帮助我们在Odoo11中创建自己的东西。
我使用以下代码但不起作用: -
In petstore/static/src/js/petstore.js:
odoo.define('tour_demo.tour', function(require) {
"use strict";
var Widget = require('web.Widget');
var core = require('web.core');
var Model = require('web.Model');
var ProductsWidget = Widget.extend({
template: "ProductsWidget",
init: function(parent, products, color) {
this._super(parent);
this.products = products;
this.corelor = color;
},
});
var HomePage = Widget.extend({
start: function() {
var products = new ProductsWidget(
this, ["cpu", "mouse", "keyboard", "graphic card",
"screen"], "#00FF00");
products.appendTo(this.$el);
},
});
core.action_registry.add('ProductsWidget', HomePage);
});
In petstore/static/src/xml/petstore.xml:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="ProductsWidget">
<div>
<t t-foreach="widget.products" t-as="product">
<span class="oe_products_item"
t-attf-style="background-color: {{ widget.color
}};">
<t t-esc="product"/>
</span>
<br/>
</t>
</div>
</t>
</templates>
In petsore/static/src/css/petstore.css:
.oe_products_item {
display: inline-block;
padding: 3px;
margin: 5px;
border: 1px solid black;
border-radius: 3px;
}
-----------------------------------------------
In views/petstore.xml:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<template id="assets_backend" name="give_name"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link href="/petstore/static/src/css/petstore.css"
rel="stylesheet"></link>
<script type="text/javascript" src="/petstore/static/src/js/petstore.js">
</script>
</xpath>
</template>
<record id="template_id" model="ir.actions.client">
<field name="name">ProductsWidget</field>
<field name="tag">ProductsWidget</field>
</record>
<menuitem id="home_page_menu" name="Home Page" action="template_id"/>
</data>
</odoo>
-----------------------------------------
__manifest__.py:
'depends': ['base',],
'data': [
'views/views.xml',
],
'qweb': ['static/src/xml/hellojs.xml'],
}
任何人都为此提供解决方案,因为我是odoo js的新手,文档也已过时,新版本非常先进(无法理解)...
答案 0 :(得分:1)
取代使用:var Model = require(&#39; web.Model&#39;);
使用:var Model = require(&#39; web.rpc&#39;);