【问题标题】:How to make a field invisible based on condition in Xml. Odoo 14如何根据 Xml 中的条件使字段不可见。奥多 14
【发布时间】:2021-02-16 18:37:22
【问题描述】:

我想在 account.payment.register 向导的继承视图中隐藏一个字段。

这里我试过了

<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>

更新模块时出错。

  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

【问题讨论】:

  • 查看日志,应该会看到Invalid composed field journal_id.type

标签: javascript python xml odoo


【解决方案1】:
_inherit = 'account.payment.register'
type = fields.selection(related='journal_id.type')

试试这个。

<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>

如果仍然出现错误,请显示日志文件。

【讨论】:

  • ,error:File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 685, in _tag_root )) from e Exception 以上异常是直接原因以下异常: Traceback(最近一次调用最后一次):文件“/usr/lib/python3/dist-packages/odoo/http.py”,第 639 行,在 _handle_exception return super(JsonRequest, self)._handle_exception(exception)文件“/usr/lib/python3/dist-packages/odoo/http.py”,第 315 行,在 _handle_exception 中引发 exception.with_traceback(None) from new_cause odoo.tools.convert.ParseError: while parsing /mnt/extra-addons /
  • 错误只是在添加时出现:attrs="{'invisible': [('journal_id.type', '=', 'bank')]}"
  • @Ing.如果您想像您一样使用隐形域,请查看我的答案。我更新了
  • @Ing 你能帮我按正确的符号吗?所以其他人可以使用它。
  • 这帮助我解决了完全相同的问题。我应该标记为答案
猜你喜欢
  • 2021-06-27
  • 2021-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多