From 9c88824ebff0d186b6b54edfe3c9799ad81432b5 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Thu, 27 Oct 2011 17:26:52 +0200 Subject: [PATCH] [REF] Add a few comments to the UoM conversion magic in the "stock available" function fields bzr revid: ls@numerigraphe.fr-20111027152652-anht8zo00pabaera --- addons/stock/product.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/stock/product.py b/addons/stock/product.py index 5341e80fb09..b3020134257 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -223,8 +223,10 @@ class product_product(osv.osv): if context.get('compute_child',True): 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 @@ -278,22 +280,26 @@ class product_product(osv.osv): 'and state in %s ' + (date_str and 'and '+date_str+' ' or '') + ' '\ 'group by product_id,product_uom',tuple(where)) results2 = cr.fetchall() + + # Get the missing UoM resources uom_obj = self.pool.get('product.uom') uoms = map(lambda x: x[2], results) + map(lambda x: x[2], results2) if context.get('uom', False): uoms += [context['uom']] - uoms = filter(lambda x: x not in uoms_o.keys(), uoms) if uoms: uoms = uom_obj.browse(cr, uid, list(set(uoms)), context=context) for o in uoms: uoms_o[o.id] = o + #TOCHECK: before change uom of product, stock move line are in old uom. context.update({'raise-exception': False}) + # Count the incoming quantities for amount, prod_id, prod_uom in results: amount = uom_obj._compute_qty_obj(cr, uid, uoms_o[prod_uom], amount, uoms_o[context.get('uom', False) or product2uom[prod_id]], context=context) res[prod_id] += amount + # Count the outgoing quantities for amount, prod_id, prod_uom in results2: amount = uom_obj._compute_qty_obj(cr, uid, uoms_o[prod_uom], amount, uoms_o[context.get('uom', False) or product2uom[prod_id]], context=context)