我正在使用Odoo 9社区版本。
在“销售订单”表单中有以下按钮:
<button name="action_confirm" states="sent" string="Confirm Sale" class="btn-primary" type="object" context="{'show_sale': True}"/>
<button name="action_confirm" states="draft" string="Confirm Sale" type="object" context="{'show_sale': True}"/>
我想把这两个按钮都藏起来。所以我尝试了下面的代码。
<record model="ir.ui.view" id="hide_so_confirm_button_form">
<field name="name">hide.so.confirm.button.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button name="action_confirm" position="attributes">
<attribute name="invisible">1</attribute>
</button>
</field>
</record>
我还尝试了以下属性:
<attribute name="states"></attribute>
对于上面的代码,它只是隐藏/影响第一个按钮。
问题:
如何隐藏两个确认销售按钮?
发布于 2016-10-21 07:13:22
没有xpath的机制只影响第一个命中。这就是为什么您必须在这里使用xpath。
另一个很好的例子(可能不再适用于Odoo 9)是在sale.order.line
窗体视图的name
字段后面设置一个新的sale.order
字段。表单视图如下所示:
<form>
<field name="name" /> <!-- sale.order name field -->
<!-- other fields -->
<field name="order_line">
<form> <!-- embedded sale.order.line form view -->
<field name="name" />
<!-- other fields -->
</form>
<tree> <!-- embedded sale.order.line tree view -->
<field name="name" />
<!-- other fields -->
</tree>
</field>
<form>
使用您的方法,可以尝试在sale.order
name
字段后面设置新字段(在本例中)。使用xpath将导致目标。
<xpath expr="//form//tree//field[@name='name']" position="after">
<field name="new_field" />
</xpath>
<xpath expr="//form//form//field[@name='name']" position="after">
<field name="new_field" />
</xpath>
因此,要直接回答你的问题(编辑):
<xpath expr="//button[@name='action_confirm' and @states='sent']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath
<xpath expr="//button[@name='action_confirm' and @states='draft']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath
发布于 2016-12-24 16:12:05
你可以使用xpath。
button[@name='action_confirm'][1]
xpath。
button[@name='action_confirm'][2]
希望它能帮上忙
发布于 2020-12-29 09:06:21
** Odoo 12
除了@CZoellner的答案,对于Odoo 12,它在view_order_form
上的定义更改为
<button name="action_confirm" id="action_confirm"
string="Confirm" class="btn-primary" type="object"
attrs="{'invisible': [('state', 'not in', ['sent'])]}"/>
<button name="action_confirm"
string="Confirm" type="object"
attrs="{'invisible': [('state', 'not in', ['draft'])]}"/>
请注意,在此更改中,不再存在states
属性。因此,为了隐藏这两个按钮,我们可以使用
<xpath expr="//button[@name='action_confirm'][1]" position="attributes">
<attribute name="attrs"></attribute>
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//button[@name='action_confirm'][2]" position="attributes">
<attribute name="attrs"></attribute>
<attribute name="invisible">1</attribute>
</xpath>
https://stackoverflow.com/questions/40170027
复制相似问题