From 0f7099bb30be0faa63f2d1f5ac1ed4dff0201cd5 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 5 Nov 2013 11:30:11 +0100 Subject: [PATCH] [FIX] sale,sale_stock: sales analysis view using incorrect JOIN and group by clause Similarly to the recent fixes in Purchase Analysis, the Sales Analysis view must not group on the quantity field. It is one of the columns that must be aggregated, not used to fold PO lines into the same result row. The line count was also incorrect because of this, and had to be corrected to actually count() the underlying SO lines. In addition, the JOINs were done in the wrong order, which could cause problems (e.g. if an empty SO ever landed in the database, all the SO line columns would be empty in the JOIN, and cause errors) bzr revid: odo@openerp.com-20131105103011-vkix07lsb6q3y9fd --- addons/sale/report/sale_report.py | 7 +++---- addons/sale_stock/report/sale_report.py | 9 +++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/sale/report/sale_report.py b/addons/sale/report/sale_report.py index 070e9c4336f..c914aba7bf6 100644 --- a/addons/sale/report/sale_report.py +++ b/addons/sale/report/sale_report.py @@ -71,7 +71,7 @@ class sale_report(osv.osv): t.uom_id as product_uom, sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty, sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total, - 1 as nbr, + count(*) as nbr, s.date_order as date, s.date_confirm as date_confirm, to_char(s.date_order, 'YYYY') as year, @@ -87,15 +87,14 @@ class sale_report(osv.osv): s.pricelist_id as pricelist_id, s.project_id as analytic_account_id from - sale_order s - join sale_order_line l on (s.id=l.order_id) + sale_order_line l + join sale_order s on (l.order_id=s.id) left join product_product p on (l.product_id=p.id) left join product_template t on (p.product_tmpl_id=t.id) left join product_uom u on (u.id=l.product_uom) left join product_uom u2 on (u2.id=t.uom_id) group by l.product_id, - l.product_uom_qty, l.order_id, t.uom_id, t.categ_id, diff --git a/addons/sale_stock/report/sale_report.py b/addons/sale_stock/report/sale_report.py index 1f1e4a625be..b7936ffe7b4 100644 --- a/addons/sale_stock/report/sale_report.py +++ b/addons/sale_stock/report/sale_report.py @@ -41,6 +41,8 @@ class sale_report(osv.osv): def init(self, cr): tools.drop_view_if_exists(cr, 'sale_report') + # TODO: make parent view extensible similarly to invoice analysis and + # remove the duplication cr.execute(""" create or replace view sale_report as ( select @@ -49,7 +51,7 @@ class sale_report(osv.osv): t.uom_id as product_uom, sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty, sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total, - 1 as nbr, + count(*) as nbr, s.date_order as date, s.date_confirm as date_confirm, to_char(s.date_order, 'YYYY') as year, @@ -67,15 +69,14 @@ class sale_report(osv.osv): s.pricelist_id as pricelist_id, s.project_id as analytic_account_id from - sale_order s - join sale_order_line l on (s.id=l.order_id) + sale_order_line l + join sale_order s on (l.order_id=s.id) left join product_product p on (l.product_id=p.id) left join product_template t on (p.product_tmpl_id=t.id) left join product_uom u on (u.id=l.product_uom) left join product_uom u2 on (u2.id=t.uom_id) group by l.product_id, - l.product_uom_qty, l.order_id, t.uom_id, t.categ_id,