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

如何查找Odoo中res.users基础视图源码以实现视图继承扩展?

Odoo res.users视图继承:定位Notebook元素解决方案

问题核心

直接使用<notebook position="inside">无法匹配原视图中的notebook元素,导致继承失效,需要通过XPath精准定位目标元素。

快速定位原视图结构(无需源码)

开启开发者模式后,按以下步骤查看原视图架构:

  • 进入「设置」→「技术」→「用户界面」→「视图」
  • 搜索视图ID base.view_users_form(模型选择res.users)
  • 打开视图详情,查看「架构」标签,找到<notebook>标签的位置,确认其在表单中的层级结构

修正后的继承代码

使用XPath匹配notebook元素,替换原代码中的<notebook>标签:

<odoo>
    <record id="res_users_view_form" model="ir.ui.view">
        <field name="model">res.users</field>
        <field name="inherit_id" ref="base.view_users_form"/>
        <field name="arch" type="xml">
            <!-- 用XPath定位表单中的notebook元素 -->
            <xpath expr="//notebook" position="inside">
                <page string="Real Estate Properties">
                    <field name="property_ids">
                        <tree decoration-success="[('state', '=', 'sold')]">
                            <field name="name"/>
                            <field name="property_type_id"/>
                            <field name="postcode"/>
                            <field name="tag_ids"/>
                            <field name="bedrooms"/>
                            <field name="living_area"/>
                            <field name="expected_price"/>
                            <field name="selling_price"/>
                        </tree>
                    </field>
                </page>
            </xpath>
        </field>
    </record>
</odoo>

进阶定位(若存在多个Notebook)

如果原视图中有多个notebook,可通过更精确的XPath缩小范围:

  • 匹配表单下的第一个notebook://form/notebook[1]
  • 结合父元素定位:比如notebook在某个group内,可写//group[@name='some_group_name']/notebook

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 14:15:59