Skip to content
Snippets Groups Projects
Commit 4261c6ba authored by Mathieu Walravens's avatar Mathieu Walravens
Browse files

[FIX] stock_account: correct value for returns


Before this commit:
When returning a transfer in AVCO/FIFO, the return's value is not always
the same as the original delivery. The unit cost for the return was
rounded, which introduced rounding errors.

After this commit:
When returning a transfer in AVCO/FIFO, the return's unit cost is not
rounded, allowing the correct value to be set.

Steps to reproduce:
1. Create a product and change its category costing method to AVCO
2. Purchase the product qty: 1 price: 13.13
3. Purchase the product qty: 1 price: 12.20
4. Sell the 2 product and deliver it
5. Create a return for the delivery
6. The value on the delivery is 25.33, but 25.34 on the return

opw-3358531

closes odoo/odoo#126546

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent 5edfd748
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ class StockMove(models.Model):
layers = layers.filtered(lambda l: float_compare(l.value, 0, precision_rounding=l.product_id.uom_id.rounding) <= 0)
layers |= layers.stock_valuation_layer_ids
quantity = sum(layers.mapped("quantity"))
return layers.currency_id.round(sum(layers.mapped("value")) / quantity) if not float_is_zero(quantity, precision_rounding=layers.uom_id.rounding) else 0
return sum(layers.mapped("value")) / quantity if not float_is_zero(quantity, precision_rounding=layers.uom_id.rounding) else 0
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
......
......@@ -580,6 +580,18 @@ class TestStockValuationAVCO(TestStockValuationCommon):
self.assertEqual(self.product1.quantity_svl, 10)
self.assertEqual(self.product1.standard_price, 2)
def test_return_delivery_rounding(self):
self.product1.product_tmpl_id.categ_id.property_valuation = 'manual_periodic'
self.product1.write({"standard_price": 1})
self._make_in_move(self.product1, 1, unit_cost=13.13)
self._make_in_move(self.product1, 1, unit_cost=12.20)
move3 = self._make_out_move(self.product1, 2, create_picking=True)
move4 = self._make_return(move3, 2)
self.assertAlmostEqual(abs(move3.stock_valuation_layer_ids[0].value), abs(move4.stock_valuation_layer_ids[0].value))
self.assertAlmostEqual(self.product1.value_svl, 25.33)
self.assertEqual(self.product1.quantity_svl, 2)
class TestStockValuationFIFO(TestStockValuationCommon):
def setUp(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment