From b5c1cb4298890e38789f56abdaf078593b0fadca Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 14 Jul 2015 09:54:37 +0200 Subject: [PATCH] [FIX] sale: Currency in Sales Analysis The "Total Price" in Sales Analysis must take into account the currency. Inspired from caf333eb59d4dc2e2eca05a0d4e8cf271b7d52cb --- addons/sale/report/sale_report.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/sale/report/sale_report.py b/addons/sale/report/sale_report.py index 9d503ff7b71..25976eaaacf 100644 --- a/addons/sale/report/sale_report.py +++ b/addons/sale/report/sale_report.py @@ -60,11 +60,20 @@ class sale_report(osv.osv): def _select(self): select_str = """ + WITH currency_rate (currency_id, rate, date_start, date_end) AS ( + SELECT r.currency_id, r.rate, r.name AS date_start, + (SELECT name FROM res_currency_rate r2 + WHERE r2.name > r.name AND + r2.currency_id = r.currency_id + ORDER BY r2.name ASC + LIMIT 1) AS date_end + FROM res_currency_rate r + ) SELECT min(l.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.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total, + sum(l.product_uom_qty * cr.rate * l.price_unit * (100.0-l.discount) / 100.0) as price_total, count(*) as nbr, s.date_order as date, s.date_confirm as date_confirm, @@ -88,6 +97,10 @@ class sale_report(osv.osv): 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) + left join product_pricelist pp on (s.pricelist_id = pp.id) + join currency_rate cr on (cr.currency_id = pp.currency_id and + cr.date_start <= coalesce(s.date_order, now()) and + (cr.date_end is null or cr.date_end > coalesce(s.date_order, now()))) """ return from_str