[FIX] Stock : Correction on average price calculation via partial pickings
authorJMA(OpenERP),RHA(OpenERP) <>
Fri, 7 Jan 2011 09:29:02 +0000 (14:59 +0530)
committerJay (OpenERP) <jvo@tinyerp.com>
Fri, 7 Jan 2011 09:29:02 +0000 (14:59 +0530)
lp bug: https://launchpad.net/bugs/688493 fixed

bzr revid: jvo@tinyerp.com-20110107092902-v420voi12bcjbt8e

addons/stock/wizard/wizard_partial_picking.py

index 7cea17b..8425814 100644 (file)
@@ -110,6 +110,7 @@ def _do_split(self, cr, uid, data, context):
 
     complete, too_many, too_few = [], [], []
     pool = pooler.get_pool(cr.dbname)
+    product_qty_avail = {}
     for move in move_obj.browse(cr, uid, data['form'].get('moves',[])):
         if move.product_qty == data['form']['move%s' % move.id]:
             complete.append(move)
@@ -134,17 +135,23 @@ def _do_split(self, cr, uid, data, context):
             currency = data['form']['currency%s' % move.id]
 
             qty = uom_obj._compute_qty(cr, uid, uom, qty, product.uom_id.id)
-
+            
+            #Updating the available quantities of product
+            if product.id in product_qty_avail.keys():
+                product_qty_avail[product.id] += qty
+            else:
+                product_qty_avail[product.id] = product.qty_available
+                
             if (qty > 0):
                 new_price = currency_obj.compute(cr, uid, currency,
                         user.company_id.currency_id.id, price)
                 new_price = uom_obj._compute_price(cr, uid, uom, new_price,
                         product.uom_id.id)
-                if product.qty_available<=0:
+                if product.qty_available <= 0:
                     new_std_price = new_price
                 else:
-                    new_std_price = ((product.standard_price * product.qty_available)\
-                        + (new_price * qty))/(product.qty_available + qty)
+                    new_std_price = ((product.standard_price * product_qty_avail[product.id])\
+                        + (new_price * qty))/(product_qty_avail[product.id] + qty)
 
                 product_obj.write(cr, uid, [product.id],
                         {'standard_price': new_std_price})