[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) <whe@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Adrien Widart
2022-02-15 15:51:56 +00:00
parent 6353fbaa06
commit 9870b42d3b
2 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -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
@@ -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):