diff --git a/addons/sale/report/sale_report.py b/addons/sale/report/sale_report.py index 09d358abdf0..1d31a7f73d3 100644 --- a/addons/sale/report/sale_report.py +++ b/addons/sale/report/sale_report.py @@ -62,17 +62,17 @@ class SaleReport(models.Model): with_ = ("WITH %s" % with_clause) if with_clause else "" select_ = """ - min(l.id) as id, + row_number() over (ORDER BY s.id) as id, l.product_id as product_id, t.uom_id as product_uom, - sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty, - sum(l.qty_delivered / u.factor * u2.factor) as qty_delivered, - sum(l.qty_invoiced / u.factor * u2.factor) as qty_invoiced, - sum(l.qty_to_invoice / u.factor * u2.factor) as qty_to_invoice, - sum(l.price_total / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as price_total, - sum(l.price_subtotal / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as price_subtotal, - sum(l.untaxed_amount_to_invoice / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as untaxed_amount_to_invoice, - sum(l.untaxed_amount_invoiced / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as untaxed_amount_invoiced, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.product_uom_qty / u.factor * u2.factor) ELSE 0 END as product_uom_qty, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.qty_delivered / u.factor * u2.factor) ELSE 0 END as qty_delivered, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.qty_invoiced / u.factor * u2.factor) ELSE 0 END as qty_invoiced, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.qty_to_invoice / u.factor * u2.factor) ELSE 0 END as qty_to_invoice, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.price_total / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as price_total, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.price_subtotal / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as price_subtotal, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.untaxed_amount_to_invoice / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as untaxed_amount_to_invoice, + CASE WHEN l.product_id IS NOT NULL THEN sum(l.untaxed_amount_invoiced / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as untaxed_amount_invoiced, count(*) as nbr, s.name as name, s.date_order as date, @@ -92,10 +92,10 @@ class SaleReport(models.Model): partner.country_id as country_id, partner.industry_id as industry_id, partner.commercial_partner_id as commercial_partner_id, - sum(p.weight * l.product_uom_qty / u.factor * u2.factor) as weight, - sum(p.volume * l.product_uom_qty / u.factor * u2.factor) as volume, + CASE WHEN l.product_id IS NOT NULL THEN sum(p.weight * l.product_uom_qty / u.factor * u2.factor) ELSE 0 END as weight, + CASE WHEN l.product_id IS NOT NULL THEN sum(p.volume * l.product_uom_qty / u.factor * u2.factor) ELSE 0 END as volume, l.discount as discount, - sum((l.price_unit * l.product_uom_qty * l.discount / 100.0 / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END)) as discount_amount, + CASE WHEN l.product_id IS NOT NULL THEN sum((l.price_unit * l.product_uom_qty * l.discount / 100.0 / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END))ELSE 0 END as discount_amount, s.id as order_id """ @@ -104,7 +104,7 @@ class SaleReport(models.Model): from_ = """ sale_order_line l - join sale_order s on (l.order_id=s.id) + right outer join sale_order s on (s.id=l.order_id) join res_partner partner on s.partner_id = partner.id left join product_product p on (l.product_id=p.id) left join product_template t on (p.product_tmpl_id=t.id) @@ -139,7 +139,7 @@ class SaleReport(models.Model): s.id %s """ % (groupby) - return '%s (SELECT %s FROM %s WHERE l.product_id IS NOT NULL GROUP BY %s)' % (with_, select_, from_, groupby_) + return '%s (SELECT %s FROM %s GROUP BY %s)' % (with_, select_, from_, groupby_) def init(self): # self._table = sale_report diff --git a/addons/sale/report/sale_report_views.xml b/addons/sale/report/sale_report_views.xml index cd2c2ec421f..9a2855e06d6 100644 --- a/addons/sale/report/sale_report_views.xml +++ b/addons/sale/report/sale_report_views.xml @@ -31,7 +31,7 @@ - +