Merge lp:~akretion-team/openobject-addons/trunk-read-for-perf into lp:openobject-addons

Proposed by Benoit Guillot - http://www.akretion.com
Status: Merged
Merged at revision: 7018
Proposed branch: lp:~akretion-team/openobject-addons/trunk-read-for-perf
Merge into: lp:openobject-addons
Diff against target: 40 lines (+10/-7)
2 files modified
product/product.py (+2/-2)
stock/product.py (+8/-5)
To merge this branch: bzr merge lp:~akretion-team/openobject-addons/trunk-read-for-perf
Reviewer Review Type Date Requested Status
qdp (OpenERP) Pending
OpenERP Core Team Pending
Review via email: mp+114000@code.launchpad.net

Description of the change

This proposal replaces the browse on the product in the method get_product_available by a read in order to greatly increase the perf. It also replaces an useless browse in the method _check_ean_key.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'product/product.py'
2--- product/product.py 2012-06-05 17:12:31 +0000
3+++ product/product.py 2012-07-09 16:21:28 +0000
4@@ -559,8 +559,8 @@
5 return False
6
7 def _check_ean_key(self, cr, uid, ids, context=None):
8- for product in self.browse(cr, uid, ids, context=context):
9- res = check_ean(product.ean13)
10+ for product in self.read(cr, uid, ids, ['ean13'], context=context):
11+ res = check_ean(product['ean13'])
12 return res
13
14 _constraints = [(_check_ean_key, 'Error: Invalid ean code', ['ean13'])]
15
16=== modified file 'stock/product.py'
17--- stock/product.py 2012-05-22 14:54:33 +0000
18+++ stock/product.py 2012-07-09 16:21:28 +0000
19@@ -243,13 +243,16 @@
20 child_location_ids = location_obj.search(cr, uid, [('location_id', 'child_of', location_ids)])
21 location_ids = child_location_ids or location_ids
22
23+ # this will be a dictionary of the product UoM by product id
24+ product2uom = {}
25+ uom_ids = []
26+ for product in self.read(cr, uid, ids, ['uom_id'], context=context):
27+ product2uom[product['id']] = product['uom_id'][0]
28+ uom_ids.append(product['uom_id'][0])
29 # this will be a dictionary of the UoM resources we need for conversion purposes, by UoM id
30 uoms_o = {}
31- # this will be a dictionary of the product UoM by product id
32- product2uom = {}
33- for product in self.browse(cr, uid, ids, context=context):
34- product2uom[product.id] = product.uom_id.id
35- uoms_o[product.uom_id.id] = product.uom_id
36+ for uom in self.pool.get('product.uom').browse(cr, uid, uom_ids, context=context):
37+ uoms_o[uom.id] = uom
38
39 results = []
40 results2 = []

Subscribers

People subscribed via source and target branches

to all changes: