From afa4c091297514b8321776d7882cea43535e4b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Fri, 12 Jul 2019 09:05:54 +0000 Subject: [PATCH] [FIX] sale: Don't compare id and NewId On runbot, edit SO131 and change the company => traceback An onchange is triggered (=> self.id is a NewId). But while recomputing the quantity delivered, a read_group is performed which gives real ids (int). The ids are then used to retrieve some so_lines in a dict where each key is an id (but actually NewId in onchange) of self. => the keys are NewIds but try to get the value with an (int) id => KeyError closes odoo/odoo#34818 Signed-off-by: Yannick Tivisse (yti) --- addons/sale/models/sale.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index f2627a1520b..574b0318b81 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1250,7 +1250,8 @@ class SaleOrderLine(models.Model): # convert uom and sum all unit_amount of analytic lines to get the delivered qty of SO lines # browse so lines and product uoms here to make them share the same prefetch - lines_map = {line.id: line for line in self} + lines = self.browse([item['so_line'][0] for item in data]) + lines_map = {line.id: line for line in lines} product_uom_ids = [item['product_uom_id'][0] for item in data if item['product_uom_id']] product_uom_map = {uom.id: uom for uom in self.env['uom.uom'].browse(product_uom_ids)} for item in data: