Rifakat (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.1-opw-575816-rha into 
lp:openobject-addons/6.1.

Requested reviews:
  Naresh(OpenERP) (nch-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-575816-rha/+merge/111031

Hello,

Whenever we cancel any ready state production order, goods were not released.
If we cancel any MO then goods should reallocated so it would not alter the 
stock levels.

The current fix, reverse the previously created Internal picking(reverse stock 
moves). 

Please review it.

Regards,
Rifakat Haradwala
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-575816-rha/+merge/111031
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.1-opw-575816-rha.
=== modified file 'mrp/mrp.py'
--- mrp/mrp.py	2012-06-01 14:32:49 +0000
+++ mrp/mrp.py	2012-06-19 14:39:29 +0000
@@ -612,6 +612,25 @@
                 line['production_id'] = production.id
                 workcenter_line_obj.create(cr, uid, line)
         return len(results)
+    
+    def _reallocate_picking(self, cr, uid, picking, context=None):
+        """ Goods remain allocated while cancelling 'ready to produce'
+        production order. It creates new picking to release the goods
+        back to stock.
+        """
+        if context is None:
+            context = {}
+        move_obj = self.pool.get('stock.move')
+        picking_obj = self.pool.get('stock.picking')
+        reallocated_picking_id = picking_obj.copy(cr, uid, picking.id, context=context)
+        for move in picking_obj.browse(cr, uid, reallocated_picking_id, context=context).move_lines:
+            move_obj.write(cr, uid, move.id, {
+                'location_id': move.location_dest_id.id,
+                'location_dest_id': move.location_id.id,
+                'state': 'done'}, context=context)
+        picking_obj.action_done(cr, uid, reallocated_picking_id, context=context)
+        return reallocated_picking_id
+        
 
     def action_cancel(self, cr, uid, ids, context=None):
         """ Cancels the production order and related stock moves.
@@ -625,6 +644,10 @@
                 raise osv.except_osv(
                     _('Could not cancel manufacturing order !'),
                     _('You must first cancel related internal picking attached to this manufacturing order.'))
+            if production.state == 'ready' and production.picking_id.state == 'done':
+                reallocated_picking_id = self._reallocate_picking(cr, uid, production.picking_id, context=context)
+                self.write(cr, uid, production.id, {'picking_id': reallocated_picking_id}, context=context)
+                
             if production.move_created_ids:
                 move_obj.action_cancel(cr, uid, [x.id for x in production.move_created_ids])
             move_obj.action_cancel(cr, uid, [x.id for x in production.move_lines])

_______________________________________________
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