From 6381b5e17171c07daa53bbd300631f5140000475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 16 Jun 2023 13:43:56 +0200 Subject: [PATCH] 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. --- modules/product_cost_history/CHANGELOG | 1 + modules/product_cost_history/product.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/product_cost_history/CHANGELOG b/modules/product_cost_history/CHANGELOG index 3562c88a13..4d7aa1d80b 100644 --- a/modules/product_cost_history/CHANGELOG +++ b/modules/product_cost_history/CHANGELOG @@ -1,3 +1,4 @@ +* Use product cost price from stock move for cost history Version 6.8.0 - 2023-05-01 -------------------------- diff --git a/modules/product_cost_history/product.py b/modules/product_cost_history/product.py index 1f6971b317..f6441bf4fa 100644 --- a/modules/product_cost_history/product.py +++ b/modules/product_cost_history/product.py @@ -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'),