From bc3a9c4f434b11caa985d1ce122b1949cad7eeb7 Mon Sep 17 00:00:00 2001 From: Benoit Guillot Date: Mon, 9 Jul 2012 15:40:24 +0200 Subject: [PATCH] [FIX] Replace browse on products by read in order to increase performances. bzr revid: benoit.guillot@akretion.com.br-20120709134024-kh03pbdc1vugca73 --- addons/product/product.py | 4 ++-- addons/stock/product.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index a81074aa56e..3cbff880cf9 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -559,8 +559,8 @@ class product_product(osv.osv): return False def _check_ean_key(self, cr, uid, ids, context=None): - for product in self.browse(cr, uid, ids, context=context): - res = check_ean(product.ean13) + for product in self.read(cr, uid, ids, ['ean13'], context=context): + res = check_ean(product['ean13']) return res _constraints = [(_check_ean_key, 'Error: Invalid ean code', ['ean13'])] diff --git a/addons/stock/product.py b/addons/stock/product.py index 62fdbb24ca2..e4164ef9e1f 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -243,13 +243,16 @@ class product_product(osv.osv): child_location_ids = location_obj.search(cr, uid, [('location_id', 'child_of', location_ids)]) location_ids = child_location_ids or location_ids - # this will be a dictionary of the UoM resources we need for conversion purposes, by UoM id - uoms_o = {} # this will be a dictionary of the product UoM by product id product2uom = {} - for product in self.browse(cr, uid, ids, context=context): - product2uom[product.id] = product.uom_id.id - uoms_o[product.uom_id.id] = product.uom_id + uom_ids = [] + for product in self.read(cr, uid, ids, ['uom_id'], context=context): + product2uom[product['id']] = product['uom_id'][0] + uom_ids.append(product['uom_id'][0]) + # this will be a dictionary of the UoM resources we need for conversion purposes, by UoM id + uoms_o = {} + for uom in self.pool.get('product.uom').browse(cr, uid, uom_ids, context=context): + uoms_o[uom.id] = uom results = [] results2 = []