跳至內容
選單
此問題已被標幟

I want to fetch sale order name, order_date from sale_order table and product name and price_total from sale_order_line table between two order_date and for a specific product_id.
Here is my code:

def _get_product_report_data(self, date_start, date_end, product_id):
product_data = []
    sale_orders = self.env['sale.order'].search(
                                [('date_order', '>=', date_start),
                         ('date_order', '<=', date_end)])
if sale_orders:
        for order in sale_orders:
so_name = order.name
            date_order = order.date_order
            order_line = self.env['sale.order.line'].search([('order_id', '=', order.id),
('product_id', '=', product_id)])
            amount = 0
            if order_line:
for line in order_line:
amount += line.price_total
product_data.append({'so_name': so_name, 'order_date': date_order,
                                    'total_amount': amount})
return product_data

How can I make this efficient? How can I grab desired data with only a single query?

頭像
捨棄

def _get_product_report_data(self, date_start, date_end, product_id):

product_data = []

order_line = self.env['sale.order.line'].search([('product_id', '=', product_id),

('order_id.date_order', '>=', date_start),

('order_id.date_order', '<=', date_end)])

Search using this Method and based on the result you have to change the product_data list filling flow.

作者

Thanks @Joby

It works!!

相關帖文 回覆 瀏覽次數 活動
1
12月 17
5756
2
1月 24
5377
0
6月 23
2001
0
3月 23
2437
1
12月 22
3310