我如何才能将所有出售给每个客户的产品都带走

时间:2019-12-16 06:48:01

标签: report odoo-10

我想将所有出售给每个客户的产品和按价格出售给他的数量都带走,但是报告并没有为我提供每个客户单独的产品

     @api.model
     def render_html(self, docids, data=None):
     self.model = self.env.context.get('active_model')
     docs = self.env[self.model].browse(self.env.context.get('active_id'))
     sales_records = []

     cr = self._cr
    query = ("""select par.name as partner_id from sale_order so 
                inner join res_partner par on (so.partner_id=par.id)
               where so.date_order >= '%s' and 
               so.date_order <= '%s' and 
               so.state = 'sale'  
               group by par.name """ % (docs.date_from, docs.date_to))
    cr.execute(query)
    orders = cr.dictfetchall()

    query2 = ( """SELECT DISTINCT sl.product_id as product_id  ,pt.name as 
product , 
        sum(product_uom_qty) as product_uom_qty ,
        sum(price_unit) as price_unit , 
        sum(price_subtotal) as price_subtotal
                        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_uom pu on sl.product_uom = pu.id
                            JOIN product_template pt ON pt.id = 
pp.product_tmpl_id
                             where so.date_order >= '%s'
                               and so.date_order <= '%s'
                               and so.state = 'sale'
                               and sl.order_partner_id=so.partner_id

                            group by 
sl.product_id,pt.name,sl.order_partner_id""" % (docs.date_from, 
docs.date_to)) 
    cr.execute(query2)
    orders2=cr.dictfetchall() 

    docargs = {
        'doc_ids': self.ids,
        'doc_model': self.model,
        'docs': docs,
        'time': time,
        'orders': orders,
        'orders2': orders2
    }
    return self.env['report'].render('sales_report.report_salesperson', 
docargs)

0 个答案:

没有答案