Use product cost price from stock move for cost history

When the product cost price is filled, it must be used instead of the cost
price.
This commit is contained in:
Cédric Krier
2023-06-16 13:43:56 +02:00
parent 7b9a61c624
commit 6381b5e171
2 changed files with 4 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
* Use product cost price from stock move for cost history
Version 6.8.0 - 2023-05-01
--------------------------
+3 -2
View File
@@ -99,14 +99,15 @@ class ProductCostHistory(ModelSQL, ModelView):
None: (move, None),
})
cost_price = Coalesce(move.product_cost_price, move.cost_price)
if database.has_window_functions():
window = Window(
[move.effective_date, move.product],
frame='ROWS', start=None, end=None,
order_by=[move.write_date.asc, move.id.asc])
cost_price = LastValue(move.cost_price, window=window)
cost_price = LastValue(cost_price, window=window)
else:
cost_price = cls.cost_price.sql_cast(move.cost_price)
cost_price = cls.cost_price.sql_cast(cost_price)
move_history = convert_from(None, tables, type_='INNER').select(
(move.id * 2).as_('id'),