我想查看基于布尔字段(基于功能)的按钮(从继承的表单),以使员工经理能够批准或拒绝员工的请假请求
views.xml
<record id="manager_approve_refuse_his_employees_leaves" model="ir.ui.view">
<field name="name">Manager Approve Refuse His Employees Leaves</field>
<field name="model">hr.holidays</field>
<field name="inherit_id" ref="hr_holidays.edit_holiday_new"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='state']" position="before">
<field name="view_leaves" invisible="0"/>
</xpath>
<xpath expr="//button[@name='action_approve']" position="attributes">
<attribute name="attrs">{'invisible': [('view_leaves' ,'=', False)]}</attribute>
</xpath>
</field>
</record>
models.py
class InheritHrHolidays(models.Model):
_inherit = 'hr.holidays'
view_leaves = fields.Boolean(compute="view_leaves_for_manager", store=False)
@api.multi
def view_leaves_for_manager(self):
if self.env.uid == self.employee_id.parent_id.user_id.id:
self.view_leaves = True
这是原始按钮
<button string="Approve" name="action_approve" states="confirm" type="object" groups="hr_holidays.group_hr_holidays_user" class="oe_highlight"/>
但是按钮尚未出现..有什么问题
在这种情况下,您首先要从按钮中删除“状态”属性,然后添加“属性”属性。例如:
<xpath expr="//button[@name='action_approve']" position="attributes">
<attribute name="states"/>
<attribute name="groups"/>
<attribute name="attrs">{'invisible': [('view_leaves' ,'=', False)]}</attribute>
</xpath>
之后,重新启动服务器和升级模块。