How to make a field invisible based on condition in Xml. Odoo 14

I want hide a field in inherited view at account.payment.register wizard.

Here I tried is

<record id="view_payment_register_form_inherit" 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">
                <field name="communication" position="after">
                    <field name="new_field"  attrs="{'invisible': [('journal_id.type', '=', 'bank')]}" />
                </field>
            </field>
        </record>

I got error when updating the module.

  f(rec)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 685, in _tag_root
    )) from e
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 639, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception
    raise exception.with_traceback(None) from new_cause
payment.xml:5, near

54 thoughts on “How to make a field invisible based on condition in Xml. Odoo 14”

  1. Try this.

    <record id="view_payment_register_form_inherit" 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="new_field"  attrs="{'invisible': [('journal_id.type', '=', 'bank')]}" />
                    </xpath>
                </field>
            </record>

    If still get error, show me the log file.

    Reply

Leave a Comment