0

I've added a new boolean field(with default False) to the sale_order and added a button to set it as True in the quotation form.

<button name="action_confirm" position="before">
     <field name="boolean_field" invisible="1"/> 
     <button name="set_boolean_field" string="Boolean Field" type="object"
        attrs="{'invisible': ['|',('boolean_field', '=', True), ('state','in',('sale','confirm'))]}"/>
 </button>

Now, I need to hide the "Confirm Sale" button, when the above boolean field is False, in the quotation form.

There are two such buttons in the form header.

<button name="action_confirm" states="sent" string="Confirm Sale" class="btn-primary o_sale_confirm" type="object"/>
<button name="action_confirm" states="draft" string="Confirm Sale" class="o_sale_confirm" type="object"/>

How do I hide the above two buttons when based on the value of boolean_field?

Thanks.

art
  • 1,358
  • 1
  • 10
  • 24

1 Answers1

1

I can't test it but I think it should be something like that.
It needs the boolean_field first.
It replaces first and second buttons attrs field. If the original buttons already have something in the attrs field then it should be added to here aswell.

<xpath expr="//button[@name='action_confirm'][1]" position="attributes">
    <attribute name="attrs">{'invisible': [('boolean_field', '=', False)]}</attribute>
</xpath>
<xpath expr="//button[@name='action_confirm'][2]" position="attributes">
    <attribute name="attrs">{'invisible': [('boolean_field', '=', False)]}</attribute>
</xpath>
Paxmees
  • 1,540
  • 1
  • 15
  • 28
  • Thanks. I had been trying this for a while but it didn't work. Got the correct way from [How can you identify multiple elements with the same name in XPath?](https://stackoverflow.com/a/322021/1472458) It should be like `expr="(//button[@name='action_confirm'])[1]"` – art May 13 '22 at 04:43