[FIX] sale: Currency in Sales Analysis
The "Total Price" in Sales Analysis must take into account the currency.
Inspired from caf333eb59
This commit is contained in:
parent
0f5a72e0a4
commit
b5c1cb4298
|
@ -60,11 +60,20 @@ class sale_report(osv.osv):
|
||||||
|
|
||||||
def _select(self):
|
def _select(self):
|
||||||
select_str = """
|
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,
|
SELECT min(l.id) as id,
|
||||||
l.product_id as product_id,
|
l.product_id as product_id,
|
||||||
t.uom_id as product_uom,
|
t.uom_id as product_uom,
|
||||||
sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
|
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,
|
count(*) as nbr,
|
||||||
s.date_order as date,
|
s.date_order as date,
|
||||||
s.date_confirm as date_confirm,
|
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_template t on (p.product_tmpl_id=t.id)
|
||||||
left join product_uom u on (u.id=l.product_uom)
|
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_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
|
return from_str
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue