首页 > 解决方案 > 如何在采购报告中打印字段product_code?

问题描述

我正在尝试自定义report_purchasequotation.xmlreport_purchaseorder.xml。我添加了一个新的th以在我的报告中添加供应商的产品参考。我的问题是当我使用span t-field="order_line.product_id.product_code"(模型 product.supplierinfo 中的字段 product_code )时,它显示错误QWebException: 'product_code'。请问有什么帮助吗?

<table class="table table-condensed">
            <thead>
                <tr>
                    <th><strong>Article</strong></th>
                    <th><strong>Référence fournisseur</strong></th>
                    <th><strong>Désignation</strong></th>
                    <th class="text-center"><strong>Expected Date</strong></th>
                    <th class="text-right"><strong>Qty</strong></th>
                </tr>
            </thead>
            <tbody>
                <tr t-foreach="o.order_line" t-as="order_line">
                    <td>
                        <span t-field="order_line.name"/>
                    </td>

                    <td>
                        <span t-field="order_line.product_id.product_code"/>
                    </td>
                    <td>

                    </td>

                    <td class="text-center">
                        <span t-field="order_line.date_planned"/>
                    </td>
                    <td class="text-right">
                        <span t-field="order_line.product_qty"/>
                        <span t-field="order_line.product_uom" groups="product.group_uom"/>
                    </td>
                </tr>
            </tbody>
        </table>

标签: pythonxmlpython-2.7odooodoo-9

解决方案


默认情况下,有一个名为的one2many字段。这就是和之间的关系。因此,您可以执行以下操作来获取所有供应商代码:product.templateseller_idsproduct_supplierinfoproduct_template

<span><t t-esc="', '.join([x.product_code for x in order_line.product_id.product_tmpl_id.seller_ids])" /></span>

您也可以在表格中显示所有产品代码

<table class="table table-condensed">
    <thead>
        <tr>
            <th>Supplier</th>
            <th>Product Code</th>
        </tr>
    </thead>
    <tbody>
        <tr t-foreach="order_line.product_id.product_tmpl_id.seller_ids" t-as="s">
            <td>
                <span t-esc="s.name.name"/>
            </td>
            <td>
                <span t-esc="s.product_code"/>
            </td>
        </tr>
    </tbody>
</table>

推荐阅读