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

在创建发票的Account Move中显示产品intrastat_id字段失败排查

问题解决:发票行Intrastat字段为空的问题

错误原因分析

你写的代码存在三个关键问题:

  • 类名与继承模型不匹配:继承account.move.line却将类命名为ProductTemplate,虽然不影响运行,但极易造成逻辑混淆。
  • 冗余且未关联的字段:account.move.line本身已自带product_id(关联product.product模型),你手动添加的product_template_id字段没有和发票行的实际产品关联,导致后续关联字段取不到值。
  • 关联路径错误:你的intra_stat字段关联的是手动添加的product_template_id.intrastat_id,但这个字段没有被自动赋值,自然显示为空。正确的关联路径应该通过发票行已有的product_id关联到产品模板。

修正后的代码

class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    intra_stat = fields.Many2one(related="product_id.product_tmpl_id.intrastat_id", string='Intrastat #')

额外说明

  1. 如果你的intrastat_id字段是直接定义在product.product(而非product.template)上,可直接将关联路径改为product_id.intrastat_id。
  2. 确保已在发票行的视图(表单/列表视图)中添加了intra_stat字段,否则即使字段逻辑正确,前端也无法显示。

内容的提问来源于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.15 18:40:32