diff options
| author | Fabien Pinckaers <fp@tinyerp.com> | 2010-03-10 16:23:52 +0100 |
|---|---|---|
| committer | Fabien Pinckaers <fp@tinyerp.com> | 2010-03-10 16:23:52 +0100 |
| commit | c8b1ffac18aaf0e1b7e944dbbd63edf00edf8941 (patch) | |
| tree | 8de94d7753b1cf39e8b026120e756b03781ed5af /addons/project_long_term/wizard/schedule_tasks.py | |
| parent | 36788afa1a982c914f41e00f9b54d579b904cce7 (diff) | |
| parent | 49738feae5ff778be8c9ca7da67ca649dc0480b2 (diff) | |
merge
bzr revid: fp@tinyerp.com-20100310152352-9a1yga9rt7aqebvv
Diffstat (limited to 'addons/project_long_term/wizard/schedule_tasks.py')
| -rw-r--r-- | addons/project_long_term/wizard/schedule_tasks.py | 92 |
1 files changed, 50 insertions, 42 deletions
diff --git a/addons/project_long_term/wizard/schedule_tasks.py b/addons/project_long_term/wizard/schedule_tasks.py index ac968e276f6..6db678333a9 100644 --- a/addons/project_long_term/wizard/schedule_tasks.py +++ b/addons/project_long_term/wizard/schedule_tasks.py @@ -23,45 +23,53 @@ import wizard import pooler from tools.translate import _ import datetime + from resource.faces import * from new import classobj import operator -import time -import project_resource as proj + +import working_calendar as wkcal success_msg = """<?xml version="1.0" ?> <form string="Compute Scheduling of Tasks"> <label string="Task Scheduling completed successfully."/> </form>""" -def resource_list(cr, uid, phase): -# To create resources which are the Project Members +class wizard_schedule_task(wizard.interface): + def _create_resources(self, cr, uid, phase, context={}): + """ + Return a list of Resource Class objects for the resources allocated to the phase. + """ resource_objs = [] for resource in phase.resource_ids: res = resource.resource_id leaves = [] resource_eff = res.time_efficiency resource_cal = res.calendar_id.id - wktime_cal = proj.compute_working_calendar(cr, uid, resource_cal) - leaves = proj.leaves_resource(cr, uid, phase.project_id.resource_calendar_id.id or False , res.id, resource_cal) - resource_objs.append(classobj(str(res.user_id.name), (Resource,), {'__doc__' : res.user_id.name, '__name__' : res.user_id.name, 'vacation' : tuple(leaves), 'efficiency' : resource_eff})) + if resource_cal: + leaves = wkcal.compute_leaves(cr, uid, phase.project_id.resource_calendar_id.id or False, res.id, resource_cal) + resource_objs.append(classobj(str(res.user_id.name), (Resource,), + {'__doc__': res.user_id.name, + '__name__': res.user_id.name, + 'vacation': tuple(leaves), + 'efficiency': resource_eff + })) return resource_objs -class wizard_schedule_task(wizard.interface): - def _compute_date(self, cr, uid, data, context): + """ + Schedule the tasks according to resource available and priority. + """ pool = pooler.get_pool(cr.dbname) - phase_pool = pool.get('project.phase') - task_pool = pool.get('project.task') - user_pool = pool.get('res.users') - phase = phase_pool.browse(cr, uid, data['id']) - task_ids = map(lambda x : x.id, (filter(lambda x : x.state in ['open','draft','pending'] , phase.task_ids))) - + phase_obj = pool.get('project.phase') + task_obj = pool.get('project.task') + user_obj = pool.get('res.users') + phase = phase_obj.browse(cr, uid, data['id'], context=context) + task_ids = map(lambda x : x.id, (filter(lambda x : x.state in ['open', 'draft', 'pending'] , phase.task_ids))) if task_ids: task_ids.sort() - tasks = task_pool.browse(cr, uid, task_ids) - wktime_cal = [] + tasks = task_obj.browse(cr, uid, task_ids, context=context) start_date = str(phase.date_start)[:-9] if not phase.date_start: if not phase.project_id.date_start: @@ -70,11 +78,10 @@ class wizard_schedule_task(wizard.interface): start_date = phase.project_id.date_start date_start = datetime.datetime.strftime(datetime.datetime.strptime(start_date, "%Y-%m-%d"), "%Y-%m-%d %H:%M") calendar_id = phase.project_id.resource_calendar_id.id - resource_objs = resource_list(cr, uid, phase) - priority_dict = {'0' :1000,'1' :800,'2' :500,'3' :300,'4' :100} - -# To create dynamic no of tasks with the resource specified - def tasks_resource(j, eff, priorty=500, obj=False): + resources = self._create_resources(cr, uid, phase) + priority_dict = {'0': 1000, '1': 800, '2': 500, '3': 300, '4': 100} + # Create dynamic no of tasks with the resource specified + def create_tasks(j, eff, priorty=500, obj=False): def task(): """ task is a dynamic method! @@ -87,44 +94,47 @@ class wizard_schedule_task(wizard.interface): task.__name__ = "task%d" %j return task -# Creating the project with all the tasks and resources + # Create a 'Faces' project with all the tasks and resources def Project(): - title = "Test Project" + title = "Project" start = date_start - resource = reduce(operator.or_, resource_objs) + try: + resource = reduce(operator.or_, resources) + except: + raise wizard.except_wizard(_('ResourceError'), _('Phase must have resources assigned !')) minimum_time_unit = 1 - -# If project has calendar - if calendar_id: - working_days = proj.compute_working_calendar(cr, uid, calendar_id) - vacation = tuple(proj.leaves_resource(cr, uid, calendar_id)) - -# Dynamic Creation of tasks + if calendar_id: # If project has working calendar + working_days = wkcal.compute_working_calendar(cr, uid, calendar_id) + vacation = tuple(wkcal.compute_leaves(cr, uid, calendar_id)) + # Dynamic creation of tasks i = 0 for each_task in tasks: hours = str(each_task.planned_hours / each_task.occupation_rate)+ 'H' if each_task.priority in priority_dict.keys(): priorty = priority_dict[each_task.priority] if each_task.user_id: - for resource_object in resource_objs: - if resource_object.__name__ == each_task.user_id.name: - task = tasks_resource(i, hours, priorty, resource_object) + for resource in resources: + if resource.__name__ == each_task.user_id.name: + task = create_tasks(i, hours, priorty, resource) else: - task = tasks_resource(i, hours, priorty) + task = create_tasks(i, hours, priorty) i += 1 -# Writing back the dates project = BalancedProject(Project) loop_no = 0 + # Write back the computed dates for t in project: s_date = t.start.to_datetime() e_date = t.end.to_datetime() if loop_no > 0: - user_id = user_pool.search(cr, uid, [('name','=',t.booked_resource[0].__name__)]) - task_pool.write(cr, uid, [tasks[loop_no-1].id], {'date_start' :s_date.strftime('%Y-%m-%d %H:%M:%S'), 'date_deadline' :e_date.strftime('%Y-%m-%d %H:%M:%S'), 'user_id' :user_id[0]}, context={'scheduler' :True}) + user_id = user_obj.search(cr, uid, [('name', '=', t.booked_resource[0].__name__)]) + task_obj.write(cr, uid, [tasks[loop_no-1].id], {'date_start': s_date.strftime('%Y-%m-%d %H:%M:%S'), + 'date_deadline': e_date.strftime('%Y-%m-%d %H:%M:%S'), + 'user_id': user_id[0]}, + context={'scheduler': True + }) loop_no +=1 return {} - states = { 'init': { 'actions': [_compute_date], @@ -132,6 +142,4 @@ class wizard_schedule_task(wizard.interface): } } wizard_schedule_task('phase.schedule.tasks') - - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
