简体   繁体   中英

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

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

In order to set conditional dynamic attributes on fields, buttons or other form elements you should rely on attrs field's attribute

 <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> 

Look here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM