2016-10-21 55 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] 

希望它有助於