2016-10-21 56 views
1

我正在使用Odoo 9社区版本。在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> 

有了上面的代码,它只是隐藏/影响第一个按钮。

问:

如何隐藏两个确认销售按钮?

回答

3

没有xpath的机制只影响第一个命中。这就是为什么你必须在这里使用xpath。

另一个很好的例子(可能不再适用于Odoo 9)是在sale.order窗体视图的name字段后面设置一个新的sale.order.line字段。 表单视图是这样的:

<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.ordername场(在这个例子中)。使用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 
-1

您可以使用XPath ...

button[@name='action_confirm'][1] 

的XPath ......

button[@name='action_confirm'][2] 

希望它有助于