0

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

khelili miliana
  • 3,730
  • 2
  • 15
  • 28

1 Answers1

0

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

Community
  • 1
  • 1
dbrus
  • 79
  • 1
  • 3