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
相关产品推荐
相关产品推荐

