From 7088b0ad9efaefcada10d391f697f887a8d8cc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 24 May 2016 16:39:35 +0200 Subject: [PATCH] [FIX] stock: quant package: issue with newId When creating a new stock.quant.package, the method tried to access a key that does not exist in an intermediate dict. Indeed a new record does not have an ID available in self.ids. --- addons/stock/models/stock_quant.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index a1bae2f240f..b0d1c2d92c1 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -589,14 +589,15 @@ class QuantPackage(models.Model): @api.depends('quant_ids.package_id', 'quant_ids.location_id', 'quant_ids.company_id', 'quant_ids.owner_id', 'ancestor_ids') def _compute_package_info(self): - res = dict.fromkeys(self.ids, {'location_id': False, 'company_id': self.env.user.company_id.id, 'owner_id': False}) + res = {} quants = self.env['stock.quant'].search([('package_id', 'in', self.ids)]) # TDE FIXME: was child_od for quant in quants: - res[quant.package_id.id].update(location_id=quant.location_id.id, owner_id=quant.owner_id.id, company_id=quant.company_id.id) + res[quant.package_id.id] = {'location_id': quant.location_id.id, 'owner_id': quant.owner_id.id, 'company_id': quant.company_id.id} for package in self: - package.location_id = res[package.id]['location_id'] - package.company_id = res[package.id]['company_id'] - package.owner_id = res[package.id]['owner_id'] + values = res.get(package.id, {'location_id': False, 'company_id': self.env.user.company_id.id, 'owner_id': False}) + package.location_id = values['location_id'] + package.company_id = values['company_id'] + package.owner_id = values['owner_id'] @api.multi def name_get(self):