客户端操作基本上是在 xml 中定义的菜单项,相应的操作被映射到一个小部件。
以下是客户端操作的实现:
您的 XML 文件将包含以下代码:
<record id="some-report-client-action" model="ir.actions.client">
<field name="name">Report Page</field>
<field name="tag">report.report_page</field>
</record>
<menuitem id="some-report-menuitem" name="Some" parent="pdf_report"
action="some-report-client-action"/>
Run Code Online (Sandbox Code Playgroud)
创建一个用于创建小部件的 js 文件。它将包含以下代码:
openerp.guard_payments = function(instance, local) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
local.HomePage = instance.Widget.extend({
template: 'MyQWebTemplate',
init: function(parent, options){
this._super.apply(this, arguments);
this.name=parent.name;
},
start: function() {
this._super.apply(this, arguments);
console.log('Widget Start')
},
});
//Following code will attach the above widget to the defined client action
instance.web.client_actions.add('report.report_page', 'instance.guard_payments.HomePage');
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我们可以创建一个完全自定义的 QWeb 模板并向其添加任何功能。
基本上这是 Odoo 提供的最好的部分