Search code examples
odoo-13qweb

Add "vendor product code" to a QWEB report in odoo 13


In the built-in sales order report, if a product has "vendor product code" set, it will show that number in front of the product's name. If it is not set, it will show the "internal reference".

We have created a new report and would like to show the internal reference/vendor product code in a column of its own.

I am unable to figure out how to reference a specific vendor for a specific product and obtain the "vendor product code". I.E. I don't know what field from what model to use.

In pseudo-code (not qweb but you get the idea):

if(sales_order_line.vendor_product_code.is_set())

    print( sales_order_line.vendor_product_code)

else

    print( sales_order_line.product.internal_id)

Solution

  • On your custom new report on the table which contain the order-line , So you can take the idea from here which test in default odoo sale order Quotation report.

    Test-Product: On the purchase tab, seller_ids have vendor set with vendor_code & default_code(internal reference) too.

    Code Example,

    <t t-foreach="doc.order_line" t-as="line">
        <t t-set="code" t-value="line.product_id.seller_ids[0].product_code if line and line.product_id and line.product_id.seller_ids and line.product_id.seller_ids[0].product_code else line.product_id.default_code"/>
        <td name="td_name"><span t-field="line.name"/><br/>Code: <span t-esc="code"/></td>
    </t>
    

    From the above code, it is just for a way to use in the report q-web, as I have used here to get the 1st seller from the multiple lists.

    so do your changes as per your customization

    Improved logic for Custom Requirement in Code:

    <t t-set="code" t-value="line.product_id.seller_ids.filtered(
                        lambda x: doc.partner_id == x.name).product_code if line and line.product_id and line.product_id.seller_ids else line.product_id.default_code"/>
    

    like this way you can check that your current partner is having the seller list. But you can add a more precise condition so for multi-partner find in seller you can not have an error with some unique condition added as per your customization.