以继承形式Odoo向按钮添加属性
Add attribute to button in inherited form Odoo
我想查看基于 bool 字段(基于功能)的按钮(来自继承的表单),以使员工经理能够批准或拒绝其员工的休假请求
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"/>
但是按钮还没有出现..
有什么问题
在这种情况下,您首先从按钮中删除 'states' 属性,然后添加 'attrs' 属性。例如:
<xpath expr="//button[@name='action_approve']" position="attributes">
<attribute name="states"/>
<attribute name="groups"/>
<attribute name="attrs">{'invisible': [('view_leaves' ,'=', False)]}</attribute>
</xpath>
之后,重启服务器并升级模块。
我想查看基于 bool 字段(基于功能)的按钮(来自继承的表单),以使员工经理能够批准或拒绝其员工的休假请求
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"/>
但是按钮还没有出现.. 有什么问题
在这种情况下,您首先从按钮中删除 'states' 属性,然后添加 'attrs' 属性。例如:
<xpath expr="//button[@name='action_approve']" position="attributes">
<attribute name="states"/>
<attribute name="groups"/>
<attribute name="attrs">{'invisible': [('view_leaves' ,'=', False)]}</attribute>
</xpath>
之后,重启服务器并升级模块。