K.ju
K.ju

Reputation: 593

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

Upvotes: 2

Views: 3393

Answers (1)

Neural
Neural

Reputation: 376

_inherit = 'account.payment.register'
type = fields.selection(related='journal_id.type')

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': [('type', '=', 'bank')]}" />
        </xpath>
    </field>
</record>

If still get error, show me the log file.

Upvotes: 4

Related Questions