Python 以继承的形式向按钮添加属性Odoo
我想查看基于bool字段(基于函数)的按钮(来自继承表单),以使员工经理能够批准或拒绝其员工的休假请求 views.xmlPython 以继承的形式向按钮添加属性Odoo,python,xml,xpath,odoo,odoo-11,Python,Xml,Xpath,Odoo,Odoo 11,我想查看基于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="mo
<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>
这是原来的按钮
<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>
{'invisible':[('view_leaves','=',False)]]
然后,重新启动服务器并升级模块。在这种情况下,您必须首先从按钮中删除“状态”属性,然后添加“属性”。例如:
<xpath expr="//button[@name='action_approve']" position="attributes">
<attribute name="states"/>
<attribute name="groups"/>
<attribute name="attrs">{'invisible': [('view_leaves' ,'=', False)]}</attribute>
</xpath>
{'invisible':[('view_leaves','=',False)]]
然后,重新启动服务器并升级模块。我从原始按钮中删除了“状态”属性,并添加了“组”属性,但仍然不起作用,因为“组”属性?是的。你说得对。我还更新了答案。它产生了Odoo服务器错误,只有人力资源官员或经理才能批准请假请求。这是一条验证消息,您必须覆盖该功能/代码/方法。请进一步解释?我从原始按钮中删除了“状态”属性,并添加了该属性,但仍然无法使用,因为组属性?是的。你说得对。我还更新了答案。它产生了Odoo服务器错误,只有人力资源官员或经理才能批准请假请求。这是验证消息,您必须覆盖该功能/代码/方法。请进一步解释?