cherry-pick of a4904fb4889c16322494981f5a1be586683704bd
Steps to reproduce the bug:
- Create a storable product “P1”
- costing method: avco
- Create a PO:
- Add the product “P1”:
- Line 1: Qty= 10, price= $50
- Line 2: Qty=1, price= $10
- Confirm the PO and receive the product
- Go to purchase → Reporting → Purchase Analysis
Problem:
The average price is incorrect, the current calculation is:
(50 + 10) / 2 = 30
The average should take into account the quantities purchased in each
line, And not simply the number of line, so the correct calculation
should be:
((10 * 50) + (10 * 1)) / 11 = 46.36
The SQL query is correct, it is when applying the read_group that the
calculation is incorrect, we should override it to make a personalized
calculation of the average.
opw-3136406
closesodoo/odoo#136097
X-original-commit: cd84549a3e5ea09d230dc1d02e05456a2372fd34
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>