You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo中继承事件视图至客户模型时遇AssertionError如何解决?

Odoo视图继承报错解决:Element odoo has extra content: data

报错信息

File "/home/abdalrahman/odoo_apps/odoo.15/15/odoo/tools/convert.py", line 748, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate)
  File "/home/abdalrahman/odoo_apps/odoo.15/15/odoo/tools/convert.py", line 797, in convert_xml_import
    relaxng.assert_(doc)
  File "src/lxml/etree.pyx", line 3633, in lxml.etree._Validator.assert_
Exception

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

Traceback (most recent call last):
  File "/home/abdalrahman/odoo_apps/odoo.15/15/odoo/http.py", line 658, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/abdalrahman/odoo_apps/odoo.15/15/odoo/http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
AssertionError: Element odoo has extra content: data, line 4

你的XML代码

<odoo>
  <data>
    <record id="view_event_form" model="ir.ui.view">
      <field name="name">event.event.form</field>
      <field name="model">event.event</field>
      <field name="inherit_id" ref="event.view_event_form"/>
      <field name="arch" type="xml"></field>
    </record>
  </data>
</odoo>

解决步骤

1. 修复标签的验证错误

Odoo 15的XML schema要求<data>标签必须携带noupdate属性(值为0或1),否则会触发RelaxNG验证失败。给<data>添加属性即可解决这个报错:

<data noupdate="0">

2. 调整视图继承目标到客户模型

你的需求是将event视图继承到客户模型(res.partner),但当前XML存在两处错误,需同步修正:

  • model字段设置为event.event,应改为res.partner
  • inherit_id引用了event的表单视图,应改为客户的基础表单视图base.view_partner_form

另外,<arch>标签不能为空,需添加具体的继承操作(比如插入字段、调整布局等),否则继承无实际意义。

修正后的XML示例:

<odoo>
  <data noupdate="0">
    <record id="view_partner_inherit_event" model="ir.ui.view">
      <field name="name">res.partner.inherit.event.form</field>
      <field name="model">res.partner</field>
      <field name="inherit_id" ref="base.view_partner_form"/>
      <field name="arch" type="xml">
        <!-- 示例:在客户表单的邮箱字段后添加关联活动的字段 -->
        <xpath expr="//field[@name='email']" position="after">
          <field name="event_ids" string="关联活动"/>
        </xpath>
      </field>
    </record>
  </data>
</odoo>

3. 补充说明

  • noupdate="0"表示该视图记录会在模块升级时更新,noupdate="1"则表示不会更新,可根据需求选择。
  • 确保你的模块已依赖base和event模块,需在__manifest__.py的depends列表中添加这两个模块。

内容的提问来源于stack exchange,提问作者sadow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 08:20:06