Ujjvala Collins (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-897082-uco into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #897082 in OpenERP Addons: "Sale: Recreate picking doesn't create correct 
picking quantity."
  https://bugs.launchpad.net/openobject-addons/+bug/897082

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-897082-uco/+merge/83553

[FIX] sale:
--------------
* Fixed the problem of recreate picking with wrong quantities when a sale order 
is in shipping exception state. 
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-897082-uco/+merge/83553
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-897082-uco.
=== modified file 'sale/sale.py'
--- sale/sale.py	2011-11-18 13:14:04 +0000
+++ sale/sale.py	2011-11-28 07:02:21 +0000
@@ -738,6 +738,27 @@
             'company_id': order.company_id.id,
         }
 
+    def ship_recreate(self, cr, uid, order, line, move_id, proc_id):
+         """
+         Define method for the process after shipping exception
+         @param order: sale order to which the order lines belong
+         @param line: sale order line
+         @move_id: newly created move id
+         @param proc_id: the ID of procurement
+         """
+         move_obj = self.pool.get('stock.move')
+         proc_obj = self.pool.get('procurement.order')
+         new_move = move_obj.browse(cr, uid, move_id)
+         if order.state == 'shipping_except':
+             for pick in order.picking_ids:
+                if pick.state == 'cancel' and pick.move_lines:
+                    move_ids = map(lambda x: x.id, pick.move_lines)
+                    for move in move_obj.browse(cr, uid, move_ids):
+                        if new_move.product_id.id == move.product_id.id:
+                            move_obj.write(cr, uid, [new_move.id], {'product_qty': move.product_qty, 'product_uos_qty': move.product_uos_qty})
+                            proc_obj.write(cr, uid, [proc_id], {'product_qty': move.product_qty, 'product_uos_qty': move.product_uos_qty})
+         return True
+
     def _create_pickings_and_procurements(self, cr, uid, order, order_lines, picking_id=False, *args):
         """Create the required procurements to supply sale order lines, also connecting
         the procurements to appropriate stock moves in order to bring the goods to the
@@ -782,18 +803,8 @@
                 proc_ids.append(proc_id)
                 line.write({'procurement_id': proc_id})
 
-                # FIXME: deals with potentially cancelled shipments, seems broken, see below
-                # FIXME: was introduced by revid: mtr@mtr-20101125100355-0a1b7m792t63mssv
                 if order.state == 'shipping_except':
-                    for pick in order.picking_ids:
-                        for move in pick.move_lines:
-                            if move.state == 'cancel':
-                                mov_ids = move_obj.search(cr, uid, [('state', '=', 'cancel'),('sale_line_id', '=', line.id),('picking_id', '=', pick.id)])
-                                if mov_ids:
-                                    for mov in move_obj.browse(cr, uid, mov_ids):
-                                        # FIXME: the following seems broken: what if move_id doesn't exist? What if there are several mov_ids? Shouldn't that be a sum?
-                                        move_obj.write(cr, uid, [move_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty})
-                                        procurement_obj.write(cr, uid, [proc_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty})
+                    self.ship_recreate(cr, uid, order, line, move_id, proc_id)
 
         wf_service = netsvc.LocalService("workflow")
         if picking_id:

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to