Skip to Content
Menu
This question has been flagged
1 Reply
2580 Views

Hi mates, I'm working product summary report for POS orders, I make a method that loop over all pos order lines and retrieve data from there, the final result should be unique product name but with the sum of sold quantities, I did it, but the output returns non-unique products and the length of the list is the summation of the order lines, I need  to remove all duplicated product and set only the last one which has the maximum quantity, here is the code 


    @api.multi
    def product_summary_test(self):
        product_summary_dict = {}
        data = []
        if self.date_from and self.date_to:
            order_detail = self.env['pos.order'].search([('date_order', '>=', self.date_from),
                                                         ('date_order', '<=', self.date_to)])
            if order_detail:
                for each_order in order_detail:
                    for each_order_line in each_order.lines:
                        if each_order_line.product_id.name in product_summary_dict:
                            product_qty = product_summary_dict[each_order_line.product_id.name]
                            product_qty += each_order_line.qty
                            res1 = {
                                "name": each_order_line.product_id.name,
                                "sold_qty": product_qty,
                            }
                            data.append(res1)
                        else:
                            product_qty = each_order_line.qty
                            res2 = {
                                "name": each_order_line.product_id.name,
                                "sold_qty": product_qty,
                            }
                            data.append(res2)
                        product_summary_dict[each_order_line.product_id.name] = product_qty;
        if data:
            print(len(data))
            print(data)
            return data
        else:
            return {}


the print for testing purpose, how can I do that ??

Avatar
Discard
Best Answer

You can use the dict to keep a track of the summary information as explained in my reply to your other post on this topic:

https://www.odoo.com/forum/help-1/question/how-to-get-unique-list-of-dictionaries-173221

Avatar
Discard
Related Posts Replies Views Activity
0
Feb 23
703
0
Jul 22
1089
1
Feb 22
6105
1
Jun 19
3135
1
Aug 21
2258