【发布时间】:2019-01-17 10:51:00
【问题描述】:
我正在尝试在树视图中选择多个员工并希望更新他们的状态(选择字段有两个选项,即出席、缺席)。
status = fields.Selection(string="Status", selection=[('present', "Present"), ('absent', "Absent")])
我的第一种方法:
我使用act_window在“动作”下拉菜单中创建当前选项(选择多个复选框时出现)
<act_window name="Present"
res_model="hr.employee"
src_model="hr.employee"
multi="True"
key2="client_action_multi"
id="employee_present"
/>
并尝试在 python 文件中为它定义一个函数,但我无法链接
act_window 到那个函数。
我的第二种方法:
然后我尝试另一种创建按钮并将其链接到 javascript 文件的方法,但这种方法也无法解决我的问题。
下面是文件hr_attendance/static/src/xml/qweb.xml的内容
<?xml version="1.0" encoding="UTF-8"?>
<templates id="sync_template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<button class="btn btn-sm btn-default sync_button" type="button">Present</button>
</t>
</t>
</templates>
下面是sync.js hr_attendance/static/src/js的内容
openerp.hr_attendance = function(instance) {
var ListView = instance.web.ListView;
console.log('Inside Javascript Code method call...');
ListView.include({
render_buttons: function() {
// GET BUTTON REFERENCE
this._super.apply(this, arguments)
if (this.$buttons) {
var btn = this.$buttons.find('.sync_button')
}
// PERFORM THE ACTION
btn.on('click', this.proxy('do_sync'))
},
do_sync: function() {
new instance.web.Model('hr.attendance')
.call('present', [[]])
.done(function() {
alert('done')
})
}
});
}
下面是我在 javascript 代码中调用的函数
@api.multi
def present(self):
self.write({'status': 'present'})
【问题讨论】:
-
请编辑您的问题,向我们展示您目前拥有的代码(与您的问题相关)。
标签: javascript xml odoo odoo-8