本章节讲述Odoo Widget的开发,假设您已经具备下述知识。
- Javascript基础和实践经验
- jQuery
- Underscore.js
并要求已安装odoo和Git。
一个简单的模块
让我们从一个基本的模块来测试web框架,该模块包含了基本的Web部分和配置,可以通过以下命令获取。
$ git clone http://github.com/odoo/petstore
将下载下来的petstore 目录不回到odoo的addons路径中,并安装petstore 模块。
查看 petstore 目录,结构如下。
oepetstore
|– images
| |– alligator.jpg
| |– ball.jpg
| |– crazy_circle.jpg
| |– fish.jpg
| -- mice.jpg
– petstore.css
|-- __init__.py
|-- oepetstore.message_of_the_day.csv
|-- __openerp__.py
|-- petstore_data.xml
|-- petstore.py
|-- petstore.xml
|-- static
|-- src
|-- css
|
|– js
| -- petstore.js
– xml
`– petstore.xml
我们的重点在static子目录。
oepetstore/static/css/petstore.css
存放css文件
oepetstore/static/xml/petstore.xml
存放 QWeb模板
oepetstore/static/js/petstore.js
最重要的部分,包含javascript的应用逻辑,目前是这个样子。
openerp.oepetstore = function(instance, local) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
local.HomePage = instance.Widget.extend({
start: function() {
console.log("pet store home page loaded");
},
});
instance.web.client_actions.add(
'petstore.homepage', 'instance.oepetstore.HomePage');
}