[FIX] stock_account: valuation history with moves having multiple quant prices

The revision 29bd622521
aimed to improve the performance by changing
the view index, to use a BIGINT instead of a text.

It was assumed that the index used
(`stock_move.id`) could not appear
multiple times with the JOINs and
group bys defined.

This was in fact possible, if a
stock move is associated to
several quants with different costs,
because of the JOIN on the many2many table
`stock_quant_move_rel`
linking quants to moves,
and the GROUP BY
`price_unit_on_quant`
that caused the different moves/quants association
not to be merged within one unique line
if the costs on the quants are different.

Instead of the group by, we now aggregate the quants
costs, using the weighted average, so the index
used can be unique, as expected.

From now, the inventory value per line in
this report view can therefore
be different than what can be found on the quants,
but this report view is based on the stock moves
rather than the stock quants, and this is therefore accepted.

In other words, the inventory value is computed for the stock move
rather than for the stock quant.

opw-658903
This commit is contained in:
Denis Ledoux 2016-02-16 16:23:05 +01:00
parent 7b445112bc
commit 1d7c12022d
1 changed files with 2 additions and 2 deletions

View File

@ -125,7 +125,7 @@ class stock_history(osv.osv):
product_categ_id,
SUM(quantity) as quantity,
date,
price_unit_on_quant,
SUM(price_unit_on_quant * quantity) / SUM(quantity) as price_unit_on_quant,
source
FROM
((SELECT
@ -193,5 +193,5 @@ class stock_history(osv.osv):
dest_location.usage not in ('internal', 'transit'))
))
AS foo
GROUP BY move_id, location_id, company_id, product_id, product_categ_id, date, price_unit_on_quant, source
GROUP BY move_id, location_id, company_id, product_id, product_categ_id, date, source
)""")