http://vitraining.com/odoo-how-to-add-custom-button-on-tree-view/
虽然已经有了 acttion_button ,见 笔记 :在layui_theme主题下添加按钮到顶部区域
这个仅供学习
xxxxxxxxxx
1
2
<templates id="sync_template" xml:space="preserve">
3
<t t-extend="ListView.buttons">
4
<t t-jquery="button.o_list_button_add" t-operation="after">
5
<t t-if="widget.model == 'hr.employee'">
6
<button class="btn btn-sm btn-default sync_button" type="button">Sync Data</button>
7
</t>
8
</t>
9
</t>
10
</templates>
XML
L1 (default)
已复制
manifest file:
xxxxxxxxxx
1
"qweb":[
2
"static/src/xml/qweb.xml",
3
],
XML
L1 (default)
已复制
添加js处理
xxxxxxxxxx
1
openerp.vit_staging = function(instance) {
2
var ListView = instance.web.ListView;
3
ListView.include({
4
render_buttons: function() {
5
​
6
// GET BUTTON REFERENCE
7
this._super.apply(this, arguments)
8
if (this.$buttons) {
9
var btn = this.$buttons.find('.sync_button')
10
}
11
​
12
// PERFORM THE ACTION
13
btn.on('click', this.proxy('do_sync'))
14
​
15
},
16
do_sync: function() {
17
new instance.web.Model('hr.employee')
18
.call('cron_process_staging', [[]])
19
.done(function(result) {
20
alert('done')
21
})
22
}
23
});
24
}
JavaScript
L1 (default)
已复制
😓 还可以这么调用模型方法。。。
new instance.web.Model('hr.employee')
.call('cron_process_staging', [[]])
.done(function(result) {
alert('done')
})