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

Odoo17企业版:XPath修改休假视图employee_ids字段失效问题

Odoo17 企业版:移除休假视图employee_ids字段创建/编辑选项无效的解决办法

问题分析

你编写的视图继承逻辑本身无错误,但在Odoo17企业版中,默认的hr_leave_view_form_manager视图优先级为16,若自定义视图优先级未超过该值,修改会被原视图覆盖导致不生效。此外还可能存在xpath定位不精确、缓存未刷新的问题。

解决步骤

1. 提高自定义视图优先级

在继承视图中添加priority字段,设置为比16更高的数值(比如20),确保你的修改能覆盖原视图:

<record id="hr_leave_view_form_manager_inherit" model="ir.ui.view">
    <field name="model">hr.leave</field>
    <field name="inherit_id" ref="hr_holidays.hr_leave_view_form_manager"/>
    <!-- 提高优先级,确保覆盖原视图 -->
    <field name="priority">20</field>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='employee_ids']" position="attributes">
            <!-- 补充no_create_edit,彻底禁用创建编辑相关操作 -->
            <attribute name="options">{'no_create': True, 'no_open': True, 'no_create_edit': True}</attribute>
        </xpath>
    </field>
</record>

2. 精确xpath定位字段

如果原视图中employee_ids字段嵌套在特定页面或分组内,模糊的xpath可能匹配不到目标字段,改用精确路径定位:

<xpath expr="//page[@name='employees']//field[@name='employee_ids']" position="attributes">
    <attribute name="options">{'no_create': True, 'no_open': True, 'no_create_edit': True}</attribute>
</xpath>

3. 强制刷新缓存并升级模块

修改完成后:

  • 进入开发者模式,勾选模块的Upgrade Database选项进行升级
  • 或者点击顶部菜单的Clear Cache按钮,强制刷新视图缓存

4. 检查是否存在其他冲突视图

在开发者模式下,进入Settings --> Technical --> User Interface --> Views,搜索hr.leave模型的form视图,找到所有继承hr_leave_view_form_manager的视图,确认你的视图优先级是最高的。如果有其他模块的同优先级或更高优先级视图,需要调整你的优先级数值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 05:02:26