Skip to content
Snippets Groups Projects
Commit 51d072db authored by Goffin Simon's avatar Goffin Simon
Browse files

[FIX] stock_account: Invalid product price history breaks stock valuation

Steps to reproduce:

1. Create a new Stockable Product
2. Set cost price to 2.00
3. Adjust stock to 10 pcs
4. Enable developer mode
5. Go to Inventory > Reports > Inventory at Date
6. Select current time and retrieve the inventory value

Bug:

The stock valuation for the product was 0.0.

Reason:

When creating a stockable product, Odoo creates
two price history entries with the same datetime
but different cost. The stock valuation report only
takes one of them into account.

Fixes #14889

opw:747857
parent aaadb232
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ class StockHistory(models.Model):
self._cr.execute("""SELECT DISTINCT ON (product_id, company_id) product_id, company_id, cost
FROM product_price_history
WHERE product_id in %s AND datetime <= %s
ORDER BY product_id, company_id, datetime DESC""", (tuple(not_real_cost_method_products.ids), date))
ORDER BY product_id, company_id, datetime DESC, id DESC""", (tuple(not_real_cost_method_products.ids), date))
for history in self._cr.dictfetchall():
histories_dict[(history['product_id'], history['company_id'])] = history['cost']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment