Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to group by of sale order line in sale order report on the basis of category of the product

By
Krupesh Laiya
on 4/22/16, 1:38 AM 454 views

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.....

1

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 4/22/16, 4:18 AM

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.

0
Krupesh Laiya
On 4/23/16, 5:06 AM

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>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/22/16, 1:38 AM
Seen: 454 times
Last updated: 4/23/16, 5:06 AM