Skip to Content
Menu
This question has been flagged

How can I print sale order line group by on the basis of product category so that the layout of the report something like below:

category-1

list of product of category-1

category-2 

list of products of category-2

and so on.....

Avatar
Discard
Best Answer

Go thought these steps:

  • Create a  method def get_category_for_so(self )  and def get_product_for_category(self,

    category)

    in sale.order.

  • Call get_category_for_so method  ,set it to a variable categories like:<t t-set="categories" t-value="o.get_category_for_so()"/>

    •  Iterate the category  like:<tr t-foreach="categories" t-as="category">

      • Call get_product_for_category method  ,set it to a variable products like:<t t-set="products" t-value="o.get_product_for_category(category)"/>

      •  Finally iterate your products like:<tr t-foreach="products" t-as="product">


Hope this may help you.

Avatar
Discard
Author Best Answer

def sort_so_line_product_category(self, lines):

    res = {}

    track_category_keys = {}

    array_index = 0

    new_res = []

    for line in lines:

    if line.product_id.categ_id.id not in track_category_keys:

        new_res.append({'cat_name': line.product_id.categ_id.name,

            'cate_total': line.price_subtotal,

            'products': [{'position': line.position_number,

            'product_name': line.product_id.name,

            'qty': line.product_uom_qty,

            'product_uom': line.product_uom.name,

            'price_unit': line.price_unit,

            'price_subtotal': line.price_subtotal,

        }]})

    track_category_keys[line.product_id.categ_id.id] = array_index

    array_index += 1

    else:

        which_key = track_category_keys[line.product_id.categ_id.id]

        new_res[which_key]['products'].append({

                'position': line.position_number,

                'product_name': line.product_id.name,

                'qty': line.product_uom_qty,

                'product_uom': line.product_uom.name,

                'price_unit': line.price_unit,

            'price_subtotal': line.price_subtotal,

            })

        new_res[which_key]['cate_total'] += line.price_subtotal

    return new_res


use that function in report view

<tbody class="sale_tbody">

<tr t-foreach="sort_so_line_product_category(o.order_line)" t-as="l">

<td>

<b><span t-esc="l['cat_name']"/></b>

</td>

<td>

</td>

<td>

</td>

<td>

</td>

<td>

</td>

<td>

</td>

<tr t-foreach="l['products']" t-as="p">

<td>

<span t-esc="p['position']"/>

</td>

<td>

<span t-esc="p['product_name']"/>

</td>

<td class="text-right">

<span t-esc="p['qty']"/>

</td>

<td class="text-right">

<span t-esc="p['product_uom']"/>

</td>

<td class="text-right">

<span t-esc="p['price_unit']"/>

</td>

<td class="text-right">

<span t-esc="p['price_subtotal']"/>

</td>

</tr>

<td>

</td>

<td>

</td>

<td>

</td>

<td>

</td>

<td class="text-right">

Total:

</td>

<td class="text-right">

<span t-esc="l['cate_total']"/>

</td>

</tr>

</tbody>

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 18
3960
1
Jan 16
5205
3
Sep 15
5188
3
Nov 19
9177
4
Nov 19
11404