From 1227e407767da810aa75a4b64ef2a335c575c00a Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 14 Jan 2020 12:18:37 +0000 Subject: [PATCH] [FIX] stock_landed_costs: prevent crash Prevent crash if `stock_valuation_layer_ids` is an empty recordset. Note that the original issue is solved with #43017, but requires an upgrade of the module. opw-2172049 closes odoo/odoo#43289 X-original-commit: 8a1ce12aee326b59f33f48804a4cfca61dab7506 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock_landed_costs/models/stock_landed_cost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock_landed_costs/models/stock_landed_cost.py b/addons/stock_landed_costs/models/stock_landed_cost.py index f65bed8b803..21b23e27aca 100644 --- a/addons/stock_landed_costs/models/stock_landed_cost.py +++ b/addons/stock_landed_costs/models/stock_landed_cost.py @@ -122,7 +122,7 @@ class LandedCost(models.Model): } for line in cost.valuation_adjustment_lines.filtered(lambda line: line.move_id): remaining_qty = sum(line.move_id.stock_valuation_layer_ids.mapped('remaining_qty')) - linked_layer = line.move_id.stock_valuation_layer_ids[0] + linked_layer = line.move_id.stock_valuation_layer_ids[:1] # Prorate the value at what's still in stock cost_to_add = (remaining_qty / line.move_id.product_qty) * line.additional_landed_cost