[IMP] Project_long_term: Refactoring Scheduling Process.
bzr revid: jam@tinyerp.com-20110105095617-bhat8tcnpqv2g5w3
This commit is contained in:
@@ -223,6 +223,7 @@ class project_phase(osv.osv):
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
resource_allocation_pool = self.pool.get('project.resource.allocation')
|
||||
uom_pool = self.pool.get('product.uom')
|
||||
task_pool = self.pool.get('project.task')
|
||||
data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day')
|
||||
for phase in self.browse(cr, uid, ids, context=context):
|
||||
avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id)
|
||||
@@ -238,14 +239,30 @@ class project_phase(osv.osv):
|
||||
'''%(phase.id, duration, str_vals or False)
|
||||
if parent:
|
||||
start = 'up.Phase_%s.end' % (parent.id)
|
||||
else:
|
||||
start = phase.project_id.date_start or phase.date_start
|
||||
#start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
s += '''
|
||||
s += '''
|
||||
start = %s
|
||||
'''%(start)
|
||||
f += s + '\n'
|
||||
else:
|
||||
start = phase.project_id.date_start or phase.date_start
|
||||
s += '''
|
||||
start = \"%s\"
|
||||
'''%(start)
|
||||
#start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
|
||||
|
||||
phase_ids.append(phase.id)
|
||||
parent = False
|
||||
task_ids = []
|
||||
todo_task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)),
|
||||
('state', 'in', ['draft', 'open', 'pending'])
|
||||
], order='sequence')
|
||||
for task in task_pool.browse(cr, uid, todo_task_ids, context=context):
|
||||
s += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=False, context=context)
|
||||
if not parent:
|
||||
parent = task
|
||||
task_ids.append(task.id)
|
||||
|
||||
f += s + '\n'
|
||||
# Recursive call till all the next phases scheduled
|
||||
for next_phase in phase.next_phase_ids:
|
||||
if next_phase.state in ['draft', 'open', 'pending']:
|
||||
@@ -256,36 +273,6 @@ class project_phase(osv.osv):
|
||||
continue
|
||||
return f, phase_ids
|
||||
|
||||
|
||||
|
||||
def schedule_tasks(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Schedule the tasks according to resource available and priority.
|
||||
"""
|
||||
task_pool = self.pool.get('project.task')
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
resources_list = self.generate_resources(cr, uid, ids, context=context)
|
||||
return_msg = {}
|
||||
for phase in self.browse(cr, uid, ids, context=context):
|
||||
start_date = phase.date_start
|
||||
if not start_date and phase.project_id.date_start:
|
||||
start_date = phase.project_id.date_start
|
||||
if not start_date:
|
||||
start_date = datetime.now().strftime("%Y-%m-%d")
|
||||
resources = resources_list.get(phase.id, [])
|
||||
calendar_id = phase.project_id.resource_calendar_id.id
|
||||
task_ids = map(lambda x : x.id, (filter(lambda x : x.state in ['draft'] , phase.task_ids))) #reassign only task not yet started
|
||||
if task_ids:
|
||||
task_pool.generate_schedule(cr, uid, task_ids, resources, calendar_id, start_date, context=context)
|
||||
|
||||
if not task_ids:
|
||||
warning_msg = _("No tasks to compute for Phase '%s'.") % (phase.name)
|
||||
if "warning" not in return_msg:
|
||||
return_msg["warning"] = warning_msg
|
||||
else:
|
||||
return_msg["warning"] = return_msg["warning"] + "\n" + warning_msg
|
||||
return return_msg
|
||||
|
||||
def schedule_tasks(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Schedule tasks base on faces lib
|
||||
@@ -300,9 +287,6 @@ class project_phase(osv.osv):
|
||||
resource_allocation_pool = self.pool.get('project.resource.allocation')
|
||||
|
||||
for phase in self.browse(cr, uid, ids, context=context):
|
||||
task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)),
|
||||
('state', 'in', ['draft', 'open', 'pending'])
|
||||
], order='sequence')
|
||||
project = phase.project_id
|
||||
calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
|
||||
start_date = project.date_start
|
||||
@@ -354,17 +338,20 @@ def Phase_%d():
|
||||
func_str += cls_str
|
||||
parent = False
|
||||
task_ids = []
|
||||
for task in task_pool.browse(cr, uid, task_ids, context=context):
|
||||
func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, context=context)
|
||||
todo_task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)),
|
||||
('state', 'in', ['draft', 'open', 'pending'])
|
||||
], order='sequence')
|
||||
for task in task_pool.browse(cr, uid, todo_task_ids, context=context):
|
||||
func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=True, context=context)
|
||||
if not parent:
|
||||
parent = task
|
||||
task_ids.append(task.id)
|
||||
|
||||
#Temp File to test the Code for the Allocation
|
||||
#fn = '/home/hmo/Desktop/plt.py'
|
||||
#fp = open(fn, 'w')
|
||||
#fp.writelines(func_str)
|
||||
#fp.close()
|
||||
# fn = '/home/hmo/Desktop/plt.py'
|
||||
# fp = open(fn, 'w')
|
||||
# fp.writelines(func_str)
|
||||
# fp.close()
|
||||
|
||||
# Allocating Memory for the required Project and Pahses and Resources
|
||||
exec(func_str)
|
||||
@@ -476,7 +463,6 @@ class project(osv.osv):
|
||||
|
||||
working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context)
|
||||
|
||||
|
||||
cls_str = ''
|
||||
# Creating Resources for the Project
|
||||
for key, vals in resource_objs.items():
|
||||
@@ -506,10 +492,10 @@ def Project_%d():
|
||||
func_str += phases
|
||||
phase_ids += child_phase_ids
|
||||
#Temp File to test the Code for the Allocation
|
||||
#fn = '/home/hmo/Desktop/plt.py'
|
||||
#fp = open(fn, 'w')
|
||||
#fp.writelines(func_str)
|
||||
#fp.close()
|
||||
fn = '/home/tiny/Desktop/plt.py'
|
||||
fp = open(fn, 'w')
|
||||
fp.writelines(func_str)
|
||||
fp.close()
|
||||
|
||||
# Allocating Memory for the required Project and Pahses and Resources
|
||||
exec(func_str)
|
||||
@@ -520,7 +506,7 @@ def Project_%d():
|
||||
phase = eval("project.Phase_%d" % phase_id)
|
||||
start_date = phase.start.to_datetime()
|
||||
end_date = phase.end.to_datetime()
|
||||
|
||||
|
||||
# Recalculate date_start and date_end
|
||||
# according to constraints on date start and date end on phase
|
||||
|
||||
@@ -560,9 +546,6 @@ def Project_%d():
|
||||
data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day')
|
||||
|
||||
for project in self.browse(cr, uid, ids, context=context):
|
||||
task_ids = task_pool.search(cr, uid, [('project_id', '=', project.id),
|
||||
('state', 'in', ['draft', 'open', 'pending'])
|
||||
], order='sequence')
|
||||
calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
|
||||
start_date = project.date_start
|
||||
#Creating resources using the member of the Project
|
||||
@@ -613,17 +596,20 @@ def Project_%d():
|
||||
func_str += cls_str
|
||||
parent = False
|
||||
task_ids = []
|
||||
for task in task_pool.browse(cr, uid, task_ids, context=context):
|
||||
func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, context=context)
|
||||
todo_task_ids = task_pool.search(cr, uid, [('project_id', '=', project.id),
|
||||
('state', 'in', ['draft', 'open', 'pending'])
|
||||
], order='sequence')
|
||||
for task in task_pool.browse(cr, uid, todo_task_ids, context=context):
|
||||
func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=True,context=context)
|
||||
if not parent:
|
||||
parent = task
|
||||
task_ids.append(task.id)
|
||||
|
||||
#Temp File to test the Code for the Allocation
|
||||
fn = '/home/hmo/Desktop/plt.py'
|
||||
fp = open(fn, 'w')
|
||||
fp.writelines(func_str)
|
||||
fp.close()
|
||||
# fn = '/home/tiny/Desktop/plt_1.py'
|
||||
# fp = open(fn, 'w')
|
||||
# fp.writelines(func_str)
|
||||
# fp.close()
|
||||
|
||||
# Allocating Memory for the required Project and Pahses and Resources
|
||||
exec(func_str)
|
||||
@@ -663,7 +649,7 @@ class project_task(osv.osv):
|
||||
'phase_id': fields.many2one('project.phase', 'Project Phase'),
|
||||
}
|
||||
|
||||
def generate_task(self, cr, uid, task_id, parent=False, context=None):
|
||||
def generate_task(self, cr, uid, task_id, parent=False, flag=False, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
@@ -674,18 +660,28 @@ class project_task(osv.osv):
|
||||
resource = False
|
||||
if len(resource_ids):
|
||||
resource = 'Resource_%s'%resource_ids[0]
|
||||
# Phases Defination for the Project
|
||||
s = '''
|
||||
# Phases Defination for the Project
|
||||
if not flag:
|
||||
s = '''
|
||||
def Task_%s():
|
||||
effort = \'%s\'
|
||||
resource = %s
|
||||
'''%(task.id, duration, resource)
|
||||
if parent:
|
||||
start = 'up.Task_%s.end' % (parent.id)
|
||||
s += '''
|
||||
start = %s
|
||||
'''%(start)
|
||||
#start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
else:
|
||||
s = '''
|
||||
def Task_%s():
|
||||
effort = \'%s\'
|
||||
resource = %s
|
||||
'''%(task.id, duration, resource)
|
||||
if parent:
|
||||
start = 'up.Task_%s.end' % (parent.id)
|
||||
else:
|
||||
start = task.project_id.date_start or task.date_start
|
||||
#start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
s += '''
|
||||
if parent:
|
||||
start = 'up.Task_%s.end' % (parent.id)
|
||||
s += '''
|
||||
start = %s
|
||||
'''%(start)
|
||||
s += '\n'
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
product_uom: product.uom_day
|
||||
project_id: project_project_worldbanksproject0
|
||||
|
||||
|
||||
|
||||
-
|
||||
Create project phase 'Establishing Project Feasibility'
|
||||
-
|
||||
@@ -66,6 +68,33 @@
|
||||
name: Procurement of Works and Goods
|
||||
product_uom: product.uom_hour
|
||||
project_id: project_project_worldbanksproject0
|
||||
|
||||
|
||||
-
|
||||
Create the phase task 'Develop GUI for Server Configuration'
|
||||
-
|
||||
!record {model: project.task, id: project_task_t0}:
|
||||
name: Develop GUI for Server Configuration
|
||||
planned_hours: 20.0
|
||||
remaining_hours: 20.0
|
||||
state: draft
|
||||
phase_id: project_phase_procurementofworksandgoods0
|
||||
project_id: project_project_worldbanksproject0
|
||||
user_id: project.res_users_analyst
|
||||
|
||||
-
|
||||
Create the phase task 'Develop GUI for Modules Configuration'
|
||||
-
|
||||
!record {model: project.task, id: project_task_t1}:
|
||||
name: Develop GUI for Modules Configuration
|
||||
planned_hours: 25.0
|
||||
remaining_hours: 25.0
|
||||
state: draft
|
||||
phase_id: project_phase_procurementofworksandgoods0
|
||||
project_id: project_project_worldbanksproject0
|
||||
user_id: project.res_users_developer
|
||||
|
||||
|
||||
|
||||
|
||||
-
|
||||
|
||||
Reference in New Issue
Block a user