[FIX] Linking Analytical Account form SO for Task
authorJigar Amin - OpenERP <jam@tinyerp.com>
Fri, 12 Aug 2011 09:30:56 +0000 (15:00 +0530)
committerJigar Amin - OpenERP <jam@tinyerp.com>
Fri, 12 Aug 2011 09:30:56 +0000 (15:00 +0530)
lp bug: https://launchpad.net/bugs/821261 fixed

bzr revid: jam@tinyerp.com-20110812093056-f63k8vnyx9cijz5n

addons/project_mrp/project_procurement.py

index 0a7fa12..1602884 100644 (file)
@@ -33,7 +33,18 @@ class procurement_order(osv.osv):
         return True
 
     def action_produce_assign_service(self, cr, uid, ids, context=None):
+        line_pool=self.pool.get('sale.order.line')
+        project_pool=self.pool.get('project.project')
         for procurement in self.browse(cr, uid, ids, context=context):
+            project_id = False
+            line_ids = line_pool.search(cr, uid , [('procurement_id', '=', procurement.id)])
+            order_lines = line_pool.browse(cr, uid, line_ids)
+            for line in order_lines:
+                if line.product_id and  line.product_id.project_id:            
+                    project_id = line.product_id.project_id.id
+                if not project_id and line.order_id.project_id:
+                    project_id = project_pool.search(cr, uid , [('name', '=', line.order_id.project_id.name)])
+                    project_id = project_id and project_id[0] or False
             self.write(cr, uid, [procurement.id], {'state': 'running'})
             planned_hours = procurement.product_qty
             task_id = self.pool.get('project.task').create(cr, uid, {
@@ -46,7 +57,7 @@ class procurement_order(osv.osv):
                 'procurement_id': procurement.id,
                 'description': procurement.note,
                 'date_deadline': procurement.date_planned,
-                'project_id': procurement.product_id.project_id and procurement.product_id.project_id.id or False,
+                'project_id':  project_id,
                 'state': 'draft',
                 'company_id': procurement.company_id.id,
             },context=context)