跳至内容
菜单
此问题已终结

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
5767
2
1月 24
5389
0
6月 23
2008
0
3月 23
2449
1
12月 22
3314