diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index eb34f637c9e..8a8e2df8c9c 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -306,18 +306,20 @@ class StockMove(models.Model): vals = {} price_unit = self._get_price_unit() value = price_unit * (quantity or valued_quantity) + value_to_return = value if quantity is None or not self.value else self.value vals = { 'price_unit': price_unit, - 'value': value if quantity is None or not self.value else self.value, + 'value': value_to_return, 'remaining_value': value if quantity is None else self.remaining_value + value, } vals['remaining_qty'] = valued_quantity if quantity is None else self.remaining_qty + quantity if self.product_id.cost_method == 'standard': value = self.product_id.standard_price * (quantity or valued_quantity) + value_to_return = value if quantity is None or not self.value else self.value vals.update({ 'price_unit': self.product_id.standard_price, - 'value': value if quantity is None or not self.value else self.value, + 'value': value_to_return, }) self.write(vals) elif self._is_out(): @@ -329,8 +331,9 @@ class StockMove(models.Model): if self.product_id.cost_method in ['standard', 'average']: curr_rounding = self.company_id.currency_id.rounding value = -float_round(self.product_id.standard_price * (valued_quantity if quantity is None else quantity), precision_rounding=curr_rounding) + value_to_return = value if quantity is None else self.value + value self.write({ - 'value': value if quantity is None else self.value + value, + 'value': value_to_return, 'price_unit': value / valued_quantity, }) elif self._is_dropshipped() or self._is_dropshipped_returned(): @@ -342,12 +345,14 @@ class StockMove(models.Model): else: price_unit = self.product_id.standard_price value = float_round(self.product_qty * price_unit, precision_rounding=curr_rounding) + value_to_return = value if self._is_dropshipped() else -value # In move have a positive value, out move have a negative value, let's arbitrary say # dropship are positive. self.write({ - 'value': value if self._is_dropshipped() else -value, + 'value': value_to_return, 'price_unit': price_unit if self._is_dropshipped() else -price_unit, }) + return value_to_return def _action_done(self): self.product_price_update_before_done()