From 977169feeb68c2df6a2a5f8b247024949633efc0 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Sat, 11 May 2019 11:20:47 +0000 Subject: [PATCH] [REF] stock_account: unit price of rereturn `_get_price_unit` is used to get the price to value a stock move and returns `unit_price` if present (most of the times it is set by purchase_stock to copy the price unit of po line) or the standard price. Note that a return copies the original move and `price_unit` is set as copy False. Before this patch, a return of a return used the standard price (due to the copy False), which doens't bring any issue but could be confusing as explained in the following receipt scenario. On a receipt, return and rereturn. The original and rereturn move may not have the same price if the standard price has changed between the operations, which is weird since there's a unit price on a potentially linked po line. On an delivery, there won't be any effect since the valuation methods do not use the result of `_get_price_unit` but force it to the standard price (standard and avco) or run fifo. task-1875873 --- addons/stock_account/models/stock_move.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index cd3c2b62870..ec632679d6d 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -32,8 +32,13 @@ class StockMove(models.Model): return action_data def _get_price_unit(self): - """ Returns the unit price to store on the quant """ - return not self.company_id.currency_id.is_zero(self.price_unit) and self.price_unit or self.product_id.standard_price + """ Returns the unit price to value this stock move """ + self.ensure_one() + price_unit = self.price_unit + # If the move is a return, use the original move's price unit. + if self.origin_returned_move_id: + price_unit = self.origin_returned_move_id.price_unit + return not self.company_id.currency_id.is_zero(price_unit) and price_unit or self.product_id.standard_price @api.model def _get_in_base_domain(self, company_id=False):