跳至内容
菜单
此问题已终结
1 回复
1524 查看

hi, this is an SQL that generates the report by Sales Order in detail.  I have made some changes to the query according to my need but now I want a summarized row that displays the sum of quantity, sub-total and total amount of all rows at the bottom.

Please help on how to achieve this.

elif data.get('report_type') == 'report_by_order_detail':

            query = '''

            SELECT  ru.id

                 so_line.product_id, res_users.partner_id, so.payment_status 

            '''         

            self._cr.execute(query)

            report_by_order_details = self._cr.dictfetchall()

            report_sub_lines.append(report_by_order_details)

形象
丢弃
最佳答案

elif data.get('report_type') == 'report_by_order_detail':


    query = '''

    SELECT

        ru.id

        so_line.product_id, 

        res_users.partner_id, 

        so.payment_status,

        so_line.quantity,

        so_line.sub_total,

        so_line.total_amount

    FROM

        your_table_name ru

    JOIN

        your_other_tables so ON ru.id = so.ru_id

    JOIN

        your_other_tables so_line ON so.id = so_line.so_id

    JOIN

        your_other_tables res_users ON so.user_id = res_users.id

    '''


    # Append GROUP BY and SUM functions for summarized row

    query += '''

    GROUP BY

        ru.id,

        so_line.product_id,

        res_users.partner_id,

        so.payment_status

    WITH ROLLUP

    '''


    self._cr.execute(query)


    report_by_order_details = self._cr.dictfetchall()


    report_sub_lines.append(report_by_order_details)


形象
丢弃
相关帖文 回复 查看 活动
0
1月 16
3702
0
8月 16
3632
0
3月 15
3727
1
4月 24
1558
4
10月 23
5789