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

Odoo中如何设置account.move的journal_id字段为可编辑?

解决Odoo视图继承修改account.move的journal_id字段无效问题

针对你遇到的视图继承修改journal_id字段attrs不生效的问题,可从以下几个方面排查修复:

1. 改用XPath精准定位字段

直接通过<field name="journal_id">定位可能出现匹配失败(比如视图存在多个同名字段、字段嵌套在特定容器中),改用XPath定位更可靠:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
    <record model="ir.ui.view" id="view_journal_allow_edit">
        <field name="name">account.journalview.form</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='journal_id']" position="attributes">
                <attribute name="attrs">{'readonly': False}</attribute>
            </xpath>
        </field>
    </record>
    </data>
</odoo>

2. 提高视图优先级

若有其他模块的视图继承也修改了该字段,优先级更高的视图会覆盖你的设置。给你的视图设置更高的priority值(默认16,数值越大优先级越高):

<record model="ir.ui.view" id="view_journal_allow_edit">
    <field name="name">account.journalview.form</field>
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_move_form"/>
    <field name="priority" eval="20"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='journal_id']" position="attributes">
            <attribute name="attrs">{'readonly': False}</attribute>
        </xpath>
    </field>
</record>

3. 清除缓存并升级模块

视图修改后Odoo可能存在缓存未更新的情况:

  • 进入开发者模式,点击顶部菜单的「Clear Cache」清除缓存
  • 重新升级你的自定义模块(路径:Settings > Apps > 找到目标模块 > Upgrade)

4. 检查是否有其他视图覆盖设置

在开发者模式下打开account.move表单视图,点击右上角「Edit > View Architecture」,查看最终生成的视图代码,确认journal_id字段的attrs是否被其他继承视图覆盖。若存在冲突,需调整对应视图优先级或修改冲突逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 17:03:31