hide lock button on sale order form based on state & condition in odoo10

时间:2018-07-16 09:23:53

标签: python xml xpath odoo-10

I'am using Odoo10 community, and I'am trying to inherit the sale order form and edit lock button, to make it visible only where state = sale and my own condition (based on an other field value ('Costum_field','=', 'Value1')).

The originale code from sale module :

<button name="action_done" type="object" string="Lock" states="sale"
    help="If the sale is locked, you can not modify it anymore. However, you will still be able to invoice or deliver."/>
<field name="state" widget="statusbar" statusbar_visible="draft,sent,sale"/>

This is my code :

<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">


    <xpath expr="//button[@name='action_done']" position="attributes">
        <attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
        <attribute name="invisible">['|' , ('state','!=', 'sale'), ('Costum_field','=', 'Value1')]</attribute>
    </xpath>

</field>

Now the button is invisble whatever the value of state and my costume field

Thank an advance

1 个答案:

答案 0 :(得分:0)

要在字段,按钮或其他表单元素上设置条件动态属性,您应该依靠attrs字段的属性

<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
    <xpath expr="//button[@name='action_done']" position="attributes">
        <attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
        <attribute name="attrs">{'invisible': ['|' , ('state','!=', 'sale'), ('Costum_field','=', 'Value1')]}</attribute>
    </xpath>
</field>

here

相关问题