Search code examples
python-2.7odoo-9

How to display product variant in report?


I have create a custom module for sale order report . In my case, articles have attributes that have more then one value for example color: red, blue. I want to display in the article description the value of the variants. I tried several code but I did not get the right result either it displays all the value of an attribute.Any idea for help please?

report_saleorder.xml

  <?xml version="1.0" encoding="utf-8"?>
 <openerp>
     <data> ...
     <table class="table table-condensed" style="margin-top:25px;">
                    <thead>
                        <tr>
                            <th>N°</th>
                            <th>REFERENCE</th>
                            <th>DESCRIPTION</th>
                            <th class="text-left">QTE</th>
                            <th class="text-left">PRIX UHT</th>
                            <th t-if="display_discount" class="text-left"
                                groups="sale.group_discount_per_so_line">
                                REMISE (%)
                            </th>
                            <th>TOTAL NET HT</th>
                            <th class="text-left">TVA</th>
                      </tr>
                    </thead>
                    <tbody class="sale_tbody">
                        <t t-foreach="doc.order_line" t-as="l">
                            <tr t-if="l.product_uom_qty">
                                <td>
                                    <span t-esc="str(l_index+1)"/>
                                </td>
                                <td>
                                    <span t-field="l.product_id.default_code"/>
                                </td>
                                            <span t-field="value.name"/>
                        <td style="width:50%;">
                                    [<span t-field="l.product_id.name"/>]
                                    <br/>
                                    <t t-foreach="l.product_id.attribute_line_ids" t-as="variant">
                                         <!-- - -->
                                        <strong><span t-field="variant.attribute_id"/>:
                                        </strong>
                                        <t t-foreach="variant.value_ids" t-as="value">
                                        <!--<span t-field="variant.value_ids.name"/>-->
                                            <span t-field="value.name"/>
                                        <!--<br/>-->
                                        </t>
                                    </t>
                                    <span t-field="l.product_id.description_sale"/>
      <td class="text-left" style="width:7%;">
                                    <span t-esc="'%.f'%(l.product_uom_qty)"/>
                                    <!--<span groups="product.group_uom" t-field="l.product_uom"/>-->
                                </td>
                                <td class="text-left" style="width:12%;">
                                    <span t-field="l.price_unit"/>
                                </td>
                                <td t-if="display_discount" class="text-left"
                                    groups="sale.group_discount_per_so_line" style="width:11%;">
                                    <span t-esc="'%.f'%(l.discount)"/>
                                </td>
                                <td style="width:15%;">
                                    <span t-field="l.price_subtotal"/>
                                </td>

                                <td class="text-left" style="width:9%">
                                    <span t-esc="', '.join(map(lambda x: (x.description or x.name), l.tax_id))"/>
                                </td>
                            </tr>
                        </t>
                    </tbody>
                </table>

Solution

  • This question is similar and somehow a duplicate of:

    (odoo10) how to add product attributes in pdf invoice

    See how to do it there