[MERGE] Merged Dhruti's branch for the fix of avoiding crash when reservation is...
authorJay Vora (OpenERP) <jvo@tinyerp.com>
Fri, 19 Aug 2011 06:41:55 +0000 (12:11 +0530)
committerJay Vora (OpenERP) <jvo@tinyerp.com>
Fri, 19 Aug 2011 06:41:55 +0000 (12:11 +0530)
bzr revid: jvo@tinyerp.com-20110819064155-7qf7zvfry302yyux

addons/mrp/mrp.py

index b8962d5..e0ce333 100644 (file)
@@ -993,8 +993,12 @@ class mrp_procurement(osv.osv):
     def action_produce_assign_product(self, cr, uid, ids, context={}):
         produce_id = False
         company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
+        move_obj = self.pool.get('stock.move')
         for procurement in self.browse(cr, uid, ids):
             res_id = procurement.move_id.id or False
+            if not res_id:
+                raise osv.except_osv(_('Warning !'), _('No reservation is defined for the selected procurement.'))
+            move_obj.write(cr, uid, [res_id],{'location_id':procurement.location_id.id})
             loc_id = procurement.location_id.id
             newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.produce_delay or 0.0)
             newdate = newdate - DateTime.RelativeDateTime(days=company.manufacturing_lead)
@@ -1017,9 +1021,6 @@ class mrp_procurement(osv.osv):
                     [produce_id], properties=[x.id for x in procurement.property_ids])
             wf_service = netsvc.LocalService("workflow")
             wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
-            if res_id:
-                self.pool.get('stock.move').write(cr, uid, [res_id],
-                    {'location_id':procurement.location_id.id})
         return produce_id
 
     def action_po_assign(self, cr, uid, ids, context={}):