[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#129025 X-original-commit: 5043b4b5099dc395234c1d5d8422b8fa7f1d94c8 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
committed by
William Henrotin
parent
bb432c2893
commit
1a85bb6f5e
@@ -51,7 +51,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 float_round(sum(layers.mapped("value")) / quantity, precision_digits=precision) 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
|
||||
|
||||
@@ -590,6 +590,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):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user