diff --git a/addons/project_mrp/mrp.py b/addons/project_mrp/mrp.py index 75a04f27872..b6aaf526720 100644 --- a/addons/project_mrp/mrp.py +++ b/addons/project_mrp/mrp.py @@ -21,6 +21,7 @@ ############################################################################## from osv import fields, osv, orm +import tools class mrp_procurement(osv.osv): _name = "mrp.procurement" @@ -38,10 +39,18 @@ class mrp_procurement(osv.osv): l = line if line.order_id.project_id: content+="\n\n"+line.order_id.project_id.complete_name - + + # Creating a project for task.Project is created from Procurement. + proj_name = tools.ustr(procurement.name) + proj_exist_id = self.pool.get('project.project').search(cr, uid, [('name','=',proj_name)], context=context) + if not proj_exist_id: + project_id = self.pool.get('project.project').create(cr, uid, {'name':proj_name}) + else: + project_id = proj_exist_id[0] + self.write(cr, uid, [procurement.id], {'state':'running'}) task_id = self.pool.get('project.task').create(cr, uid, { - 'name': (procurement.origin or procurement.product_id.name) +': '+(procurement.name or ''), + 'name': '%s:%s' %(procurement.product_id.name or procurement.origin, procurement.name or ''), 'date_deadline': procurement.date_planned, 'planned_hours': procurement.product_qty, 'remaining_hours': procurement.product_qty, @@ -51,8 +60,9 @@ class mrp_procurement(osv.osv): 'description': content, 'date_deadline': procurement.date_planned, 'state': 'draft', - 'partner_id': l and l.order_id.partner_id.id or False - }) + 'partner_id': l and l.order_id.partner_id.id or False, + 'project_id': project_id, + },context=context) return task_id mrp_procurement()