[IMP] project_long_term: refector scheduling of phase/task process to make compatable with faces lib
bzr revid: hmo@tinyerp.com-20110105090552-s65bdri5j4nr09qh
This commit is contained in:
@@ -40,9 +40,9 @@ Features.
|
||||
"init_xml": [],
|
||||
"demo_xml": ["project_long_term_demo.xml"],
|
||||
"test": [
|
||||
'test/test_project_long_term.yml',
|
||||
'test/schedule_project_phases.yml',
|
||||
'test/schedule_project_tasks.yml',
|
||||
'test/test_project_long_term.yml',
|
||||
'test/schedule_phase_tasks.yml',
|
||||
'test/test_schedule_phases_case1.yml',
|
||||
'test/test_schedule_phases_case2.yml',
|
||||
|
||||
@@ -215,18 +215,6 @@ class project_phase(osv.osv):
|
||||
self.write(cr, uid, ids, {'state': 'done'})
|
||||
return True
|
||||
|
||||
def generate_resources(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Return a list of Resource Class objects for the resources allocated to the phase.
|
||||
"""
|
||||
|
||||
res = {}
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
for phase in self.browse(cr, uid, ids, context=context):
|
||||
resource_objs = map(lambda x:x.resource_id.name, phase.resource_ids)
|
||||
res[phase.id] = resource_objs
|
||||
return res
|
||||
|
||||
def generate_phase(self, cr, uid, ids, f, parent=False, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
@@ -236,7 +224,7 @@ class project_phase(osv.osv):
|
||||
resource_allocation_pool = self.pool.get('project.resource.allocation')
|
||||
uom_pool = self.pool.get('product.uom')
|
||||
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)[::-1]:
|
||||
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)
|
||||
duration = str(avg_days) + 'd'
|
||||
# Create a new project for each phase
|
||||
@@ -250,7 +238,10 @@ class project_phase(osv.osv):
|
||||
'''%(phase.id, duration, str_vals or False)
|
||||
if parent:
|
||||
start = 'up.Phase_%s.end' % (parent.id)
|
||||
s += '''
|
||||
else:
|
||||
start = phase.project_id.date_start or phase.date_start
|
||||
#start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
s += '''
|
||||
start = %s
|
||||
'''%(start)
|
||||
f += s + '\n'
|
||||
@@ -265,114 +256,7 @@ class project_phase(osv.osv):
|
||||
continue
|
||||
return f, phase_ids
|
||||
|
||||
def generate_schedule(self, cr, uid, root_phase, start_date=False, calendar_id=False, context=None):
|
||||
"""
|
||||
Schedule phase with the start date till all the next phases are completed.
|
||||
@param: start_date (datetime.datetime) : start date for the phase. It would be either Start date of phase or start date of project or system current date
|
||||
@param: calendar_id : working calendar of the project
|
||||
"""
|
||||
func_str = ''
|
||||
if context is None:
|
||||
context = {}
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
resource_allocation_pool = self.pool.get('project.resource.allocation')
|
||||
uom_pool = self.pool.get('product.uom')
|
||||
data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day')
|
||||
|
||||
|
||||
if not start_date:
|
||||
start_date = root_phase.project_id.date_start or root_phase.date_start or datetime.now().strftime("%Y-%m-%d")
|
||||
start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
|
||||
start = start_date
|
||||
minimum_time_unit = 1
|
||||
working_hours_per_day = 24
|
||||
working_days_per_week = 7
|
||||
working_days_per_month = 30
|
||||
working_days_per_year = 365
|
||||
|
||||
vacation = []
|
||||
if calendar_id:
|
||||
working_hours_per_day = 8 #TODO: it should be come from calendars
|
||||
working_days_per_week = 5
|
||||
working_days_per_month = 20
|
||||
working_days_per_year = 200
|
||||
vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id))
|
||||
working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context)
|
||||
|
||||
#Creating resources using the member of the Project
|
||||
u_ids = [i.id for i in root_phase.project_id.members]
|
||||
resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context)
|
||||
cls_str = ''
|
||||
# Creating Resources for the Project
|
||||
for key, vals in resource_objs.items():
|
||||
cls_str +='''
|
||||
class Resource_%s(Resource):
|
||||
vacation = %s
|
||||
efficiency = %s
|
||||
'''%(key, vals.get('vacation', False), vals.get('efficiency', False))
|
||||
|
||||
# Create a new project for each phase
|
||||
func_str += '''
|
||||
|
||||
def Project_%d():
|
||||
# If project has working calendar then that
|
||||
# else the default one would be considered
|
||||
start = \'%s\'
|
||||
minimum_time_unit = %s
|
||||
working_hours_per_day = %s
|
||||
working_days_per_week = %s
|
||||
working_days_per_month = %s
|
||||
working_days_per_year = %s
|
||||
vacation = %s
|
||||
working_days = %s
|
||||
from resource.faces import Resource
|
||||
'''%(root_phase.project_id.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days )
|
||||
func_str += cls_str
|
||||
phases, phase_ids = self.generate_phase(cr, uid, [root_phase.id], func_str, context=context)
|
||||
#Temp File to test the Code for the Allocation
|
||||
# fn = '/home/tiny/Desktop/plt.py'
|
||||
# fp = open(fn, 'w')
|
||||
# fp.writelines(phases)
|
||||
# fp.close()
|
||||
# Allocating Memory for the required Project and Pahses and Resources
|
||||
exec(phases)
|
||||
Project = eval('Project_%d' % root_phase.project_id.id)
|
||||
project = Task.BalancedProject(Project)
|
||||
|
||||
for phase_id in phase_ids:
|
||||
phase = eval("project.Phase_%d" % phase_id)
|
||||
start_date = phase.start.to_datetime()
|
||||
end_date = phase.end.to_datetime()
|
||||
# print phase_id,"\n\n****Phases *********", phase.resource
|
||||
# Recalculate date_start and date_end
|
||||
# according to constraints on date start and date end on phase
|
||||
|
||||
# if phase.constraint_date_start and str(s_date) < phase.constraint_date_start:
|
||||
# start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d')
|
||||
# else:
|
||||
# start_date = s_date
|
||||
# if phase.constraint_date_end and str(e_date) > phase.constraint_date_end:
|
||||
# end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d')
|
||||
# date_start = phase.constraint_date_end
|
||||
# else:
|
||||
# end_date = e_date
|
||||
# date_start = end_date
|
||||
# # Write the calculated dates back
|
||||
# ctx = context.copy()
|
||||
# ctx.update({'scheduler': True})
|
||||
self.write(cr, uid, [phase_id], {
|
||||
'date_start': start_date.strftime('%Y-%m-%d'),
|
||||
'date_end': end_date.strftime('%Y-%m-%d')
|
||||
}, context=context)
|
||||
# write dates into Resources Allocation
|
||||
# for resource in phase.resource_ids:
|
||||
# resource_allocation_pool.write(cr, uid, [resource.id], {
|
||||
# 'date_start': start_date.strftime('%Y-%m-%d'),
|
||||
# 'date_end': end_date.strftime('%Y-%m-%d')
|
||||
# }, context=context)
|
||||
# # Recursive call till all the next phases scheduled
|
||||
|
||||
|
||||
def schedule_tasks(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
@@ -401,6 +285,102 @@ def Project_%d():
|
||||
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
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if type(ids) in (long, int,):
|
||||
ids = [ids]
|
||||
task_pool = self.pool.get('project.task')
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
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
|
||||
#Creating resources using the member of the Project
|
||||
u_ids = [i.id for i in project.members]
|
||||
resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context)
|
||||
start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
func_str = ''
|
||||
start = start_date
|
||||
minimum_time_unit = 1
|
||||
# default values
|
||||
working_hours_per_day = 24
|
||||
working_days_per_week = 7
|
||||
working_days_per_month = 30
|
||||
working_days_per_year = 365
|
||||
|
||||
vacation = []
|
||||
if calendar_id:
|
||||
working_hours_per_day = 8 #TODO: it should be come from calendars
|
||||
working_days_per_week = 5
|
||||
working_days_per_month = 20
|
||||
working_days_per_year = 200
|
||||
vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context))
|
||||
|
||||
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():
|
||||
cls_str +='''
|
||||
class Resource_%s(Resource):
|
||||
vacation = %s
|
||||
efficiency = %s
|
||||
'''%(key, vals.get('vacation', False), vals.get('efficiency', False))
|
||||
|
||||
# Create a new project for each phase
|
||||
func_str += '''
|
||||
def Phase_%d():
|
||||
from resource.faces import Resource
|
||||
start = \'%s\'
|
||||
minimum_time_unit = %s
|
||||
working_hours_per_day = %s
|
||||
working_days_per_week = %s
|
||||
working_days_per_month = %s
|
||||
working_days_per_year = %s
|
||||
vacation = %s
|
||||
working_days = %s
|
||||
'''%(phase.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days )
|
||||
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)
|
||||
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()
|
||||
|
||||
# Allocating Memory for the required Project and Pahses and Resources
|
||||
exec(func_str)
|
||||
Phase = eval('Phase_%d' % phase.id)
|
||||
phase = Task.BalancedProject(Phase)
|
||||
|
||||
for task_id in task_ids:
|
||||
task = eval("phase.Task_%d" % task_id)
|
||||
start_date = task.start.to_datetime()
|
||||
end_date = task.end.to_datetime()
|
||||
|
||||
task_pool.write(cr, uid, [task_id], {
|
||||
'date_start': start_date.strftime('%Y-%m-%d'),
|
||||
'date_end': end_date.strftime('%Y-%m-%d')
|
||||
}, context=context)
|
||||
return True
|
||||
project_phase()
|
||||
|
||||
class project_resource_allocation(osv.osv):
|
||||
@@ -452,54 +432,214 @@ class project(osv.osv):
|
||||
|
||||
def schedule_phases(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Schedule the phases.
|
||||
Schedule phase base on faces lib
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if type(ids) in (long, int,):
|
||||
ids = [ids]
|
||||
phase_pool = self.pool.get('project.phase')
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
resource_allocation_pool = self.pool.get('project.resource.allocation')
|
||||
uom_pool = self.pool.get('product.uom')
|
||||
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):
|
||||
phase_ids = phase_pool.search(cr, uid, [('project_id', '=', project.id),
|
||||
root_phase_ids = phase_pool.search(cr, uid, [('project_id', '=', project.id),
|
||||
('state', 'in', ['draft', 'open', 'pending']),
|
||||
('previous_phase_ids', '=', False)
|
||||
])
|
||||
calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
|
||||
start_date = False
|
||||
for phase in phase_pool.browse(cr, uid, phase_ids, context=context):
|
||||
phase_pool.generate_schedule(cr, uid, phase, start_date, calendar_id, context=context)
|
||||
return True
|
||||
start_date = project.date_start
|
||||
#if start_date:
|
||||
# start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
#Creating resources using the member of the Project
|
||||
u_ids = [i.id for i in project.members]
|
||||
resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context)
|
||||
func_str = ''
|
||||
start = start_date
|
||||
minimum_time_unit = 1
|
||||
# default values
|
||||
working_hours_per_day = 24
|
||||
working_days_per_week = 7
|
||||
working_days_per_month = 30
|
||||
working_days_per_year = 365
|
||||
|
||||
vacation = []
|
||||
if calendar_id:
|
||||
working_hours_per_day = 8 #TODO: it should be come from calendars
|
||||
working_days_per_week = 5
|
||||
working_days_per_month = 20
|
||||
working_days_per_year = 200
|
||||
vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context))
|
||||
|
||||
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():
|
||||
cls_str +='''
|
||||
class Resource_%s(Resource):
|
||||
vacation = %s
|
||||
efficiency = %s
|
||||
'''%(key, vals.get('vacation', False), vals.get('efficiency', False))
|
||||
|
||||
# Create a new project for each phase
|
||||
func_str += '''
|
||||
def Project_%d():
|
||||
from resource.faces import Resource
|
||||
start = \'%s\'
|
||||
minimum_time_unit = %s
|
||||
working_hours_per_day = %s
|
||||
working_days_per_week = %s
|
||||
working_days_per_month = %s
|
||||
working_days_per_year = %s
|
||||
vacation = %s
|
||||
working_days = %s
|
||||
'''%(project.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days )
|
||||
func_str += cls_str
|
||||
phase_ids = []
|
||||
for root_phase in phase_pool.browse(cr, uid, root_phase_ids, context=context):
|
||||
phases, child_phase_ids = phase_pool.generate_phase(cr, uid, [root_phase.id], '', context=context)
|
||||
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()
|
||||
|
||||
# Allocating Memory for the required Project and Pahses and Resources
|
||||
exec(func_str)
|
||||
Project = eval('Project_%d' % project.id)
|
||||
project = Task.BalancedProject(Project)
|
||||
|
||||
for phase_id in phase_ids:
|
||||
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
|
||||
|
||||
#if phase.constraint_date_start and str(s_date) < phase.constraint_date_start:
|
||||
# start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d')
|
||||
#else:
|
||||
# start_date = s_date
|
||||
#if phase.constraint_date_end and str(e_date) > phase.constraint_date_end:
|
||||
# end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d')
|
||||
# date_start = phase.constraint_date_end
|
||||
#else:
|
||||
# end_date = e_date
|
||||
# date_start = end_date
|
||||
|
||||
# Write the calculated dates back
|
||||
#ctx = context.copy()
|
||||
#ctx.update({'scheduler': True})
|
||||
phase_pool.write(cr, uid, [phase_id], {
|
||||
'date_start': start_date.strftime('%Y-%m-%d'),
|
||||
'date_end': end_date.strftime('%Y-%m-%d')
|
||||
}, context=context)
|
||||
return True
|
||||
|
||||
def schedule_tasks(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Schedule the tasks according to resource available and priority.
|
||||
Schedule task base on faces lib
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if type(ids) in (long, int,):
|
||||
ids = [ids]
|
||||
user_pool = self.pool.get('res.users')
|
||||
task_pool = self.pool.get('project.task')
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
resources_list = self.generate_members(cr, uid, ids, context=context)
|
||||
return_msg = {}
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
resource_allocation_pool = self.pool.get('project.resource.allocation')
|
||||
uom_pool = self.pool.get('product.uom')
|
||||
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):
|
||||
start_date = project.date_start
|
||||
if not start_date:
|
||||
start_date = datetime.now().strftime("%Y-%m-%d")
|
||||
resources = resources_list.get(project.id, [])
|
||||
calendar_id = project.resource_calendar_id.id
|
||||
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
|
||||
u_ids = [i.id for i in project.members]
|
||||
resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context)
|
||||
start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d")
|
||||
func_str = ''
|
||||
start = start_date
|
||||
minimum_time_unit = 1
|
||||
# default values
|
||||
working_hours_per_day = 24
|
||||
working_days_per_week = 7
|
||||
working_days_per_month = 30
|
||||
working_days_per_year = 365
|
||||
|
||||
vacation = []
|
||||
if calendar_id:
|
||||
working_hours_per_day = 8 #TODO: it should be come from calendars
|
||||
working_days_per_week = 5
|
||||
working_days_per_month = 20
|
||||
working_days_per_year = 200
|
||||
vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context))
|
||||
|
||||
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():
|
||||
cls_str +='''
|
||||
class Resource_%s(Resource):
|
||||
vacation = %s
|
||||
efficiency = %s
|
||||
'''%(key, vals.get('vacation', False), vals.get('efficiency', False))
|
||||
|
||||
# Create a new project for each phase
|
||||
func_str += '''
|
||||
def Project_%d():
|
||||
from resource.faces import Resource
|
||||
start = \'%s\'
|
||||
minimum_time_unit = %s
|
||||
working_hours_per_day = %s
|
||||
working_days_per_week = %s
|
||||
working_days_per_month = %s
|
||||
working_days_per_year = %s
|
||||
vacation = %s
|
||||
working_days = %s
|
||||
'''%(project.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days )
|
||||
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)
|
||||
if not parent:
|
||||
parent = task
|
||||
task_ids.append(task.id)
|
||||
|
||||
if task_ids:
|
||||
task_pool.generate_schedule(cr, uid, task_ids, resources, calendar_id, start_date, context=context)
|
||||
else:
|
||||
warning_msg = _("No tasks to compute for Project '%s'.") % (project.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
|
||||
#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()
|
||||
|
||||
# Allocating Memory for the required Project and Pahses and Resources
|
||||
exec(func_str)
|
||||
Project = eval('Project_%d' % project.id)
|
||||
project = Task.BalancedProject(Project)
|
||||
|
||||
for task_id in task_ids:
|
||||
task = eval("project.Task_%d" % task_id)
|
||||
start_date = task.start.to_datetime()
|
||||
end_date = task.end.to_datetime()
|
||||
|
||||
task_pool.write(cr, uid, [task_id], {
|
||||
'date_start': start_date.strftime('%Y-%m-%d'),
|
||||
'date_end': end_date.strftime('%Y-%m-%d')
|
||||
}, context=context)
|
||||
return True
|
||||
|
||||
project()
|
||||
|
||||
@@ -523,87 +663,32 @@ class project_task(osv.osv):
|
||||
'phase_id': fields.many2one('project.phase', 'Project Phase'),
|
||||
}
|
||||
|
||||
def generate_schedule(self, cr, uid, ids, resources, calendar_id, start_date, context=None):
|
||||
"""
|
||||
Schedule the tasks according to resource available and priority.
|
||||
"""
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
if not ids:
|
||||
return False
|
||||
def generate_task(self, cr, uid, task_id, parent=False, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
user_pool = self.pool.get('res.users')
|
||||
project_pool = self.pool.get('project.project')
|
||||
priority_dict = {'0': 1000, '1': 800, '2': 500, '3': 300, '4': 100}
|
||||
# Create dynamic no of tasks with the resource specified
|
||||
def create_tasks(task_number, eff, priorty=500, obj=False):
|
||||
def task():
|
||||
"""
|
||||
task is a dynamic method!
|
||||
"""
|
||||
effort = eff
|
||||
if obj:
|
||||
resource = obj
|
||||
priority = priorty
|
||||
task.__doc__ = "TaskNO%d" %task_number
|
||||
task.__name__ = "task%d" %task_number
|
||||
return task
|
||||
|
||||
# Create a 'Faces' project with all the tasks and resources
|
||||
def Project():
|
||||
title = "Project"
|
||||
start = datetime.strftime(datetime.strptime(start_date, "%Y-%m-%d"), "%Y-%m-%d %H:%M")
|
||||
try:
|
||||
resource = reduce(operator.or_, resources)
|
||||
except:
|
||||
raise osv.except_osv(_('Error'), _('Resources should be allocated to your phases and Members should be assigned to your Project!'))
|
||||
minimum_time_unit = 1
|
||||
working_hours_per_day = 24
|
||||
working_days_per_week = 7
|
||||
working_days_per_month = 30
|
||||
working_days_per_year = 365
|
||||
vacation = []
|
||||
if calendar_id:
|
||||
working_hours_per_day = 8 #TODO: it should be come from calendars
|
||||
working_days_per_week = 5
|
||||
working_days_per_month = 20
|
||||
working_days_per_year = 200
|
||||
vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context))
|
||||
working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context)
|
||||
# Dynamic creation of tasks
|
||||
task_number = 0
|
||||
for openobect_task in self.browse(cr, uid, ids, context=context):
|
||||
hours = str(openobect_task.planned_hours )+ 'H'
|
||||
if openobect_task.priority in priority_dict.keys():
|
||||
priorty = priority_dict[openobect_task.priority]
|
||||
real_resource = False
|
||||
if openobect_task.user_id:
|
||||
for task_resource in resources:
|
||||
if task_resource.__name__ == task_resource:
|
||||
real_resource = task_resource
|
||||
break
|
||||
|
||||
task = create_tasks(task_number, hours, priorty, real_resource)
|
||||
task_number += 1
|
||||
|
||||
|
||||
face_projects = Task.BalancedProject(Project)
|
||||
loop_no = 0
|
||||
# Write back the computed dates
|
||||
for face_project in face_projects:
|
||||
s_date = face_project.start.to_datetime()
|
||||
e_date = face_project.end.to_datetime()
|
||||
if loop_no > 0:
|
||||
ctx = context.copy()
|
||||
ctx.update({'scheduler': True})
|
||||
user_id = user_pool.search(cr, uid, [('name', '=', face_project.booked_resource[0].__name__)])
|
||||
self.write(cr, uid, [ids[loop_no-1]], {
|
||||
'date_start': s_date.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'date_end': e_date.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'user_id': user_id[0]
|
||||
}, context=ctx)
|
||||
|
||||
loop_no += 1
|
||||
return True
|
||||
resource_pool = self.pool.get('resource.resource')
|
||||
resource_allocation_pool = self.pool.get('project.resource.allocation')
|
||||
task = self.browse(cr, uid, task_id, context=context)
|
||||
duration = str(task.planned_hours )+ 'H'
|
||||
resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id)], context=context)
|
||||
resource = False
|
||||
if len(resource_ids):
|
||||
resource = 'Resource_%s'%resource_ids[0]
|
||||
# Phases Defination for the Project
|
||||
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 += '''
|
||||
start = %s
|
||||
'''%(start)
|
||||
s += '\n'
|
||||
return s
|
||||
project_task()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user