Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1518 Lượt xem

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)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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)


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 16
3702
0
thg 8 16
3630
0
thg 3 15
3719
1
thg 4 24
1554
4
thg 10 23
5783