Skip to Content
Menu
This question has been flagged
2 Replies
24643 Views

Hello Community ,I'm facing a probleme ,i want to create an invoice wich show the list of product sales grouped by category 

i tried this

<t t-foreach="o.order_line" t-as="l">

<t t-if="l.product_id.categ_id">

<tr>  <td>

<span t-field="l.product_id.categ_id"/>

</td> </tr> </t>


but dosen't groub all products it show this result:

category 1

product 1

category 1

product 2


i want this resulat 

category 1

product 1

product 2

etc ...

thanks in advance


Avatar
Discard
Best Answer

Here is the code for grouping...

<t t-set="product_category" t-value="[]"/>

<t t-foreach="o.order_line" t-as="l">

<t t-set="product_category" t-value="product_category+[l.product_id.categ_id]"/>

</t>

<t t-foreach="set(product_category)" t-as="category">

<div><strong t-esc="category.name"/></div>

<t t-foreach="o.order_line" t-as="l">

<t t-if="category.id==l.product_id.categ_id.id">

<div><span t-field="l.product_id"/></div>

</t>

</t>

</t>

Avatar
Discard

Thanks so much Jusab. Big help.

This idea remains valid 8 years later with Odoo 17. It has been a great help. Thank you!

Best Answer

Hello,
what have I to do group on main product that has several optional products connected ?
Now I got something like this in Order and Invoice.
Main product x ------ 0
Opt prod 1 --- 10€
Opt prod 3 --- 22€
.... so on

I would like to have a grouping on main product like this 

Main product x ------ 32€
Main product y ------ 56€
Main product z ------ 34€
Totale ----------------122€

Thanks

Avatar
Discard