← Back to team overview

openerp-wms-expert team mailing list archive

lp:~openerp-wms-expert/openobject-addons/7.0_partial_picking_uses_product into lp:openobject-addons/7.0

 

Lorenzo Battistini - Agile BG has proposed merging lp:~openerp-wms-expert/openobject-addons/7.0_partial_picking_uses_product into lp:openobject-addons/7.0.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #1179923 in OpenERP Addons: "stock partial picking does not consider product changed"
  https://bugs.launchpad.net/openobject-addons/+bug/1179923

For more details, see:
https://code.launchpad.net/~openerp-wms-expert/openobject-addons/7.0_partial_picking_uses_product/+merge/163699
-- 
https://code.launchpad.net/~openerp-wms-expert/openobject-addons/7.0_partial_picking_uses_product/+merge/163699
Your team OpenERP WMS Expert is subscribed to branch lp:~openerp-wms-expert/openobject-addons/7.0_partial_picking_uses_product.
=== modified file 'stock/stock.py'
--- stock/stock.py	2013-04-25 12:49:33 +0000
+++ stock/stock.py	2013-05-14 12:37:51 +0000
@@ -1230,7 +1230,7 @@
         for pick in self.browse(cr, uid, ids, context=context):
             new_picking = None
             complete, too_many, too_few = [], [], []
-            move_product_qty, prodlot_ids, product_avail, partial_qty, product_uoms = {}, {}, {}, {}, {}
+            move_product_qty, prodlot_ids, product_avail, partial_qty, product_uoms, product_ids = {}, {}, {}, {}, {}, {}
             for move in pick.move_lines:
                 if move.state in ('done', 'cancel'):
                     continue
@@ -1238,11 +1238,13 @@
                 product_qty = partial_data.get('product_qty',0.0)
                 move_product_qty[move.id] = product_qty
                 product_uom = partial_data.get('product_uom',False)
+                product_id = partial_data.get('product_id',False)
                 product_price = partial_data.get('product_price',0.0)
                 product_currency = partial_data.get('product_currency',False)
                 prodlot_id = partial_data.get('prodlot_id')
                 prodlot_ids[move.id] = prodlot_id
                 product_uoms[move.id] = product_uom
+                product_ids[move.id] = product_id
                 partial_qty[move.id] = uom_obj._compute_qty(cr, uid, product_uoms[move.id], product_qty, move.product_uom.id)
                 if move.product_qty == partial_qty[move.id]:
                     complete.append(move)
@@ -1252,8 +1254,8 @@
                     too_many.append(move)
 
                 # Average price computation
-                if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
-                    product = product_obj.browse(cr, uid, move.product_id.id)
+                product = product_obj.browse(cr, uid, product_id)
+                if (pick.type == 'in') and (product.cost_method == 'average'):
                     move_currency_id = move.company_id.currency_id.id
                     context['currency_id'] = move_currency_id
                     qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
@@ -1307,7 +1309,8 @@
                             'state': 'assigned',
                             'move_dest_id': False,
                             'price_unit': move.price_unit,
-                            'product_uom': product_uoms[move.id]
+                            'product_uom': product_uoms[move.id],
+                            'product_id': product_ids[move.id],
                     }
                     prodlot_id = prodlot_ids[move.id]
                     if prodlot_id:
@@ -1324,16 +1327,19 @@
             if new_picking:
                 move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking})
             for move in complete:
-                defaults = {'product_uom': product_uoms[move.id], 'product_qty': move_product_qty[move.id]}
+                defaults = {'product_uom': product_uoms[move.id], 'product_qty': move_product_qty[move.id], 'product_id': product_ids[move.id]}
                 if prodlot_ids.get(move.id):
                     defaults.update({'prodlot_id': prodlot_ids[move.id]})
                 move_obj.write(cr, uid, [move.id], defaults)
             for move in too_many:
                 product_qty = move_product_qty[move.id]
+                product_uom = product_uoms[move.id]
+                product_id = product_ids[move.id]
                 defaults = {
                     'product_qty' : product_qty,
                     'product_uos_qty': product_qty, #TODO: put correct uos_qty
-                    'product_uom': product_uoms[move.id]
+                    'product_uom': product_uom,
+                    'product_id': product_id,
                 }
                 prodlot_id = prodlot_ids.get(move.id)
                 if prodlot_ids.get(move.id):
@@ -2646,6 +2652,8 @@
         complete, too_many, too_few = [], [], []
         move_product_qty = {}
         prodlot_ids = {}
+        product_uoms = {}
+        product_ids = {}
         for move in self.browse(cr, uid, ids, context=context):
             if move.state in ('done', 'cancel'):
                 continue
@@ -2654,9 +2662,12 @@
             product_qty = partial_data.get('product_qty',0.0)
             move_product_qty[move.id] = product_qty
             product_uom = partial_data.get('product_uom',False)
+            product_id = partial_data.get('product_id',False)
             product_price = partial_data.get('product_price',0.0)
             product_currency = partial_data.get('product_currency',False)
             prodlot_ids[move.id] = partial_data.get('prodlot_id')
+            product_uoms[move.id] = product_uom
+            product_ids[move.id] = product_id
             if move.product_qty == product_qty:
                 complete.append(move)
             elif move.product_qty > product_qty:
@@ -2665,8 +2676,8 @@
                 too_many.append(move)
 
             # Average price computation
-            if (move.picking_id.type == 'in') and (move.product_id.cost_method == 'average'):
-                product = product_obj.browse(cr, uid, move.product_id.id)
+            product = product_obj.browse(cr, uid, product_id)
+            if (move.picking_id.type == 'in') and (product.cost_method == 'average'):
                 move_currency_id = move.company_id.currency_id.id
                 context['currency_id'] = move_currency_id
                 qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
@@ -2694,6 +2705,8 @@
 
         for move in too_few:
             product_qty = move_product_qty[move.id]
+            product_uom = product_uoms[move.id]
+            product_id = product_ids[move.id]
             if product_qty != 0:
                 defaults = {
                             'product_qty' : product_qty,
@@ -2702,6 +2715,8 @@
                             'state': 'assigned',
                             'move_dest_id': False,
                             'price_unit': move.price_unit,
+                            'product_uom': product_uom,
+                            'product_id': product_id,
                             }
                 prodlot_id = prodlot_ids[move.id]
                 if prodlot_id:
@@ -2726,8 +2741,13 @@
             complete.append(move)
 
         for move in complete:
+            move_vals = {
+                'product_uom': product_uoms[move.id],
+                'product_id': product_ids[move.id],
+                }
             if prodlot_ids.get(move.id):
-                self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id)})
+                move_vals['prodlot_id'] = prodlot_ids.get(move.id)
+            self.write(cr, uid, [move.id], move_vals)
             self.action_done(cr, uid, [move.id], context=context)
             if  move.picking_id.id :
                 # TOCHECK : Done picking if all moves are done