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

如何为One2Many字段下的特定字段设置只读并解决QWeb2报错?

Fixing QWeb2 Runtime Error: Unknown Field in Domain for One2Many Field Readonly Setting

Hey there, let's break down why you're hitting this error and how to fix it. The error unknown field od_confirm_state_line happens because either your domain is referencing a field that doesn't exist in the right model, or you're using the wrong syntax for the domain in your One2Many tree view.

First, Let's Diagnose the Root Causes

  • Field Doesn't Exist in the Child Model: The field od_confirm_state_line needs to be present on the model that your cost_line One2Many field points to (e.g., if cost_line links to account.landed.cost.line, check if that model actually has od_confirm_state_line defined). Double-check for typos—underscores, capitalization, or missing suffixes/prefixes are common culprits.
  • Incorrect Domain Syntax: Odoo expects domain conditions to be a list of tuples, not a list of lists like you wrote ([["od_confirm_state_line","=","confirmed"]]). Also, when setting readonly on a field inside the One2Many's tree view, you're working in the context of the child record, so you can directly reference the child model's fields without extra prefixes (unless you need to pull a value from the parent model—then use parent.).

Corrected Code Example

Let's assume you want to set a specific field (say product_id) to readonly when od_confirm_state_line is confirmed on the child record. Here's how your XML should look:

<page string="Landed Cost">
    <field name="cost_line">
        <tree editable="bottom">
            <!-- Target field with corrected readonly domain -->
            <field name="product_id" readonly="[('od_confirm_state_line', '=', 'confirmed')]"/>
            <!-- Optional: Include the state field in the tree for testing visibility -->
            <field name="od_confirm_state_line"/>
            <!-- Add your remaining fields here -->
        </tree>
    </field>
</page>

If you need to base the readonly state on a field from the parent model (not the child), adjust the domain to use the parent. prefix:

<field name="product_id" readonly="[('parent.od_parent_confirm_state', '=', 'confirmed')]"/>

Quick Verification Checklist

  • Confirm od_confirm_state_line exists on the child model linked by cost_line
  • Fix the domain syntax to use tuples instead of nested lists
  • If referencing parent model fields, add the parent. prefix to the field name

That should resolve the QWeb2 runtime error and get your readonly logic working as expected.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 07:43:33