Need to pass list of ids to sql query in where clause. product_id is many2many field. My code is
query = """
SELECT pt.name as product,sl.price_unit as price,sum(sl.qty_invoiced) as quantity from sale_order_line sl
JOIN sale_order so ON so.id = sl.order_id
JOIN product_product pp ON pp.id = sl.product_id
JOIN product_template pt ON pt.id = pp.product_tmpl_id
WHERE so.date_order >='"""+str(obj.start_date)+"""'
and so.date_order <= '"""+str(obj.end_date)+"""'
and so.partner_id ="""+str(obj.customer_id.id)+"""
and sl.invoice_status = 'invoiced'
"""
if obj.product_id:
query +=""" and sl.product_id in """+str(obj.product_id.ids)
query += """GROUP BY product,price"""
syntax error sl.product_id in [13017, 11253, 1395] near '['