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

Odoo13中如何为QWEB报告新增vendor product code展示列

Odoo13自定义销售订单报告产品编码字段说明与实现方案

对应字段说明

  • 供应商产品编码(vendor product code):存储在product.supplierinfo模型的product_code字段,该模型为产品的供应商信息子表,关联产品变体(product.product)或产品模板(product.template)
  • 内部参考编码(internal reference):存储在product.product模型的default_code字段,就是你提到的internal_id

报告模板实现逻辑

你可以直接在销售订单的QWeb报告模板中加入以下代码,无需修改后端Python逻辑即可实现需求:

<!-- 销售订单行遍历节点下新增列 -->
<td>
    <t t-set="first_supplier_code" t-value="line.product_id.seller_ids and line.product_id.seller_ids[0].product_code or ''"/>
    <t t-if="first_supplier_code">
        <span t-esc="first_supplier_code"/>
    </t>
    <t t-else="">
        <span t-esc="line.product_id.default_code"/>
    </t>
</td>

上述代码默认取产品优先级最高的供应商对应的编码,如果需要指定特定供应商的编码,可改用以下过滤逻辑:

<td>
    <!-- 将下方123替换为你要匹配的供应商数据库ID -->
    <t t-set="target_supplier_id" t-value="123"/>
    <t t-set="matched_supplier" t-value="line.product_id.seller_ids.filtered(lambda s: s.name.id == target_supplier_id)"/>
    <t t-set="supplier_code" t-value="matched_supplier and matched_supplier[0].product_code or ''"/>
    <t t-if="supplier_code">
        <span t-esc="supplier_code"/>
    </t>
    <t t-else="">
        <span t-esc="line.product_id.default_code"/>
    </t>
</td>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 06:15:07