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

在stock.inventory.line视图显示自定义产品字段报错求助

问题分析与解决方案

错误根源

你错误重定义了stock.inventory.line的product_id字段,将其关联目标从**product.product(产品变体)改为product.template(产品模板)**。而stock.inventory.line自带的outdated字段依赖stock_move_ids,该字段仅存在于product.product模型中,product.template无此字段,因此触发报错。

修改步骤

1. 修正Python代码

删除重定义的product_id字段,调整instrument_field的关联路径,通过原product_id(指向product.product)关联到产品模板:

from odoo import models, fields

class StockInventoryLine(models.Model):
    _inherit = 'stock.inventory.line'

    instrument_field = fields.Many2one(related='product_id.product_tmpl_id.instrument', string='Instrument')

2. 保留原有XML视图代码

你的XML视图继承代码无需修改,调整Python代码后即可正常渲染自定义字段。

3. 前置验证

确保:

  • 模块依赖配置无问题(当前depends配置符合要求)
  • product.template模型上确实存在instrument自定义字段(需确认该字段已在其他模块中定义完成)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 21:15:11