← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~yann-papouin/ocb-addons/6.1-bug-899470-stock-product-available-optimization into lp:ocb-addons/6.1

 

Yann Papouin has proposed merging lp:~yann-papouin/ocb-addons/6.1-bug-899470-stock-product-available-optimization into lp:ocb-addons/6.1.

Requested reviews:
  OpenERP Community Backports Team (ocb)
Related bugs:
  Bug #899470 in OpenERP Community Backports (Addons): "[6.0][6.1][stock] get_product_available needs optimization"
  https://bugs.launchpad.net/ocb-addons/+bug/899470

For more details, see:
https://code.launchpad.net/~yann-papouin/ocb-addons/6.1-bug-899470-stock-product-available-optimization/+merge/205200

Backport from existing functionality in 6.0/7.0/trunk
-- 
https://code.launchpad.net/~yann-papouin/ocb-addons/6.1-bug-899470-stock-product-available-optimization/+merge/205200
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~yann-papouin/ocb-addons/6.1-bug-899470-stock-product-available-optimization into lp:ocb-addons/6.1.
=== modified file 'stock/product.py'
--- stock/product.py	2012-07-05 08:27:08 +0000
+++ stock/product.py	2014-02-06 16:00:18 +0000
@@ -185,6 +185,7 @@
         location_obj = self.pool.get('stock.location')
         warehouse_obj = self.pool.get('stock.warehouse')
         shop_obj = self.pool.get('sale.shop')
+        uom_obj = self.pool.get('product.uom')
         
         states = context.get('states',[])
         what = context.get('what',())
@@ -222,13 +223,15 @@
             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
+        # Extract UoM id from product ids 
+        product2uom = {}
+        for product in self.read(cr, uid, ids, ['uom_id'], context=context):
+            product2uom[product['id']] = product['uom_id'][0]
+            
+        # Create a dict of the UoM resources by id that we need for conversion purposes
         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
+        for uom in uom_obj.browse(cr, uid, product2uom.values(), context=context):
+            uoms_o[uom.id] = uom
 
         results = []
         results2 = []


Follow ups