From 9870b42d3b95bdadfa6894c1a346fe3284dd2842 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Tue, 8 Feb 2022 17:28:06 +0000 Subject: [PATCH] [FIX] stock_account: return product with PU equal to zero To reproduce the issue: (Need purchase,sale_management) 1. Create a product category PC: - Costing Method: FIFO 2. Create a product P - Type: Storable - Category: PC 3. Create a PO with 1 x P @ 10 + Receive P 4. Create a PO with 1 x P @ 0 + Receive P 5. Create a SO with 1 x P + Deliver P 6. Create a SO with 1 x P + Deliver P 7. Process a return for sold P at step 6 8. Open the valuation of the return Error: The value is 10, should be 0 In `_get_price_unit`, `price_unit` is defined with the correct value (i.e., `0`), but the if-condition of the `return` is not respected, so another value is used OPW-2735502 closes odoo/odoo#84649 X-original-commit: 3ad98f7da027829c563fb9ebc86e8299721743db Signed-off-by: William Henrotin (whe) Signed-off-by: Adrien Widart --- addons/stock_account/models/stock_move.py | 2 +- .../stock_account/tests/test_stockvaluationlayer.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index 7ba1144f46c..829d15ac0d5 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -45,7 +45,7 @@ class StockMove(models.Model): precision = self.env['decimal.precision'].precision_get('Product Price') # If the move is a return, use the original move's price unit. if self.origin_returned_move_id and self.origin_returned_move_id.sudo().stock_valuation_layer_ids: - price_unit = self.origin_returned_move_id.sudo().stock_valuation_layer_ids[-1].unit_cost + return self.origin_returned_move_id.sudo().stock_valuation_layer_ids[-1].unit_cost return price_unit if not float_is_zero(price_unit, precision) or self._should_force_price_unit() else self.product_id.standard_price @api.model diff --git a/addons/stock_account/tests/test_stockvaluationlayer.py b/addons/stock_account/tests/test_stockvaluationlayer.py index eb095226613..871c75a7bf6 100644 --- a/addons/stock_account/tests/test_stockvaluationlayer.py +++ b/addons/stock_account/tests/test_stockvaluationlayer.py @@ -678,6 +678,17 @@ class TestStockValuationFIFO(TestStockValuationCommon): self.assertEqual(self.product1.quantity_svl, 2) self.assertAlmostEqual(self.product1.standard_price, 10) + def test_return_delivery_2(self): + self._make_in_move(self.product1, 1, unit_cost=10) + self.product1.standard_price = 0 + self._make_in_move(self.product1, 1, unit_cost=0) + + self._make_out_move(self.product1, 1) + out_move02 = self._make_out_move(self.product1, 1, create_picking=True) + + returned = self._make_return(out_move02, 1) + self.assertEqual(returned.stock_valuation_layer_ids.value, 0) + class TestStockValuationChangeCostMethod(TestStockValuationCommon): def test_standard_to_fifo_1(self):