Help

0

How to make invisible Field Odoo 14

Avatar
Cristina.J

In register payment wizard , I added 2 fields. I want to make fields invisibles according to 'move_type', using :   
attrs='{"invisible":[('move_type', '=' ,'in_invoice')]}'

 attrs='{"invisible":[('move_type', '=' ,'out_invoice')]}'


if move_type == 'in_invoice' --> field1 : invisible

if move_type == 'out_invoice' --> field2 : invisible


<record id="view_account_payment_register_form_inherit_payment_test" model="ir.ui.view">

  <field name="name">account.payment.register.form.inherit.payment.test</field>

  <field name="model">account.payment.register</field>

  <field name="inherit_id" ref="account.view_account_payment_register_form"/>

  <field name="arch" type="xml">

      <xpath expr="//group/field[@name='communication']" position="after">

          <field name="field1"/>

          <field name="field2"/>

       </xpath>

 </field>

</record>


How can I do it ? Thanks.

1 Comment
Avatar
Discard
Avatar
Karan BK
-

I don't know what problem you're having because by using 

<field name="field1" attrs="{'invisible': [('move_type',  '=', 'in_invoice')]}" />

<field name="field2" attrs="{'invisible': [('move_type',  '=', 'out_invoice')]}" />

It should have worked. But if you're trying to change the visibility of a field which is already in view that you're inheriting you may want to use 

<field name="field1" position="attributes">

    <attribute name="attrs">[('move_type', '=', 'in_invoice')]</attribute>

</field>

Can you specify more about the problem here.

1 Answer
0
Best Answer

Hi,

Please try the below code,

<record id="view_account_payment_register_form_inherit_payment_test" model="ir.ui.view">

      <field name="name">account.payment.register.form.inherit.payment.test</field>

      <field name="model">account.payment.register</field>

      <field name="inherit_id" ref="account.view_account_payment_register_form"/>

      <field name="arch" type="XML">

          <xpath expr="//group/field[@name='communication']" position="after">

              <field name="field1" attrs="{'invisible': [('move_type',  '=', 'in_invoice')]}" />

            <field name="field2" attrs="{'invisible': [('move_type',  '=', 'out_invoice')]}" />

           </xpath>

     </field>

</record>


or refer this link

https://www.odoo.com/forum/help-1/how-to-make-a-field-invisible-based-on-condition-in-xml-139634


Thanks

Muhammed Ali M - iWesabe

Avatar
Discard