From 4f7ece5e75b7cb0dbd730fbb9f4a5119c5d7d7b2 Mon Sep 17 00:00:00 2001 From: "mra (Open ERP)" Date: Tue, 16 Mar 2010 15:00:14 +0530 Subject: [PATCH] [IMP] project_long_term: improve the code bzr revid: mra@tinyerp.com-20100316093014-m1t1z0nb8j05s8x9 --- addons/project_long_term/project_long_term.py | 8 ++++++-- .../project_long_term/wizard/compute_phases_date.py | 4 ++-- .../project_long_term/wizard/compute_tasks_date.py | 13 +++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 48129f40bb8..ea11df9f9bd 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -136,7 +136,9 @@ class project_phase(osv.osv): calendar_id = phase.project_id.resource_calendar_id and phase.project_id.resource_calendar_id.id or False resource_id = resource_obj.search(cr, uid, [('user_id', '=', phase.responsible_id.id)]) if resource_id: - cal_id = resource_obj.browse(cr, uid, resource_id[0], context=context).calendar_id.id +# cal_id = resource_obj.browse(cr, uid, resource_id[0], context=context).calendar_id.id + res = resource_obj.read(cr, uid, resource_id[0], ['calendar_id'], context=context)[0] + cal_id = res.get('calendar_id', False) and res.get('calendar_id')[0] or False if cal_id: calendar_id = cal_id default_uom_id = uom_obj.search(cr, uid, [('name', '=', 'Hour')], context=context)[0] @@ -155,7 +157,9 @@ class project_phase(osv.osv): calendar_id = phase.project_id.resource_calendar_id and phase.project_id.resource_calendar_id.id or False resource_id = resource_obj.search(cr, uid, [('user_id', '=', phase.responsible_id.id)], context=context) if resource_id: - cal_id = resource_obj.browse(cr, uid, resource_id[0], context=context).calendar_id.id +# cal_id = resource_obj.browse(cr, uid, resource_id[0], context=context).calendar_id.id + res = resource_obj.read(cr, uid, resource_id[0], ['calendar_id'], context=context)[0] + cal_id = res.get('calendar_id', False) and res.get('calendar_id')[0] or False if cal_id: calendar_id = cal_id default_uom_id = uom_obj.search(cr, uid, [('name', '=', 'Hour')], context=context)[0] diff --git a/addons/project_long_term/wizard/compute_phases_date.py b/addons/project_long_term/wizard/compute_phases_date.py index f684871e636..3893628bacf 100644 --- a/addons/project_long_term/wizard/compute_phases_date.py +++ b/addons/project_long_term/wizard/compute_phases_date.py @@ -135,8 +135,8 @@ class wizard_compute_phases(wizard.interface): ('previous_phase_ids', '=', False) ], context=context) phase_ids.sort() - phase_objs = phase_obj.browse(cr, uid, phase_ids, context=context) - for phase in phase_objs: + phases = phase_obj.browse(cr, uid, phase_ids, context=context) + for phase in phases: start_date = phase.project_id.date_start if not phase.project_id.date_start: start_date = datetime.datetime.now().strftime("%Y-%m-%d") diff --git a/addons/project_long_term/wizard/compute_tasks_date.py b/addons/project_long_term/wizard/compute_tasks_date.py index 1187980057b..42d8e6f9242 100644 --- a/addons/project_long_term/wizard/compute_tasks_date.py +++ b/addons/project_long_term/wizard/compute_tasks_date.py @@ -61,7 +61,7 @@ class wizard_compute_tasks(wizard.interface): ]) if task_ids: task_ids.sort() - task_objs = task_pool.browse(cr, uid, task_ids, context=context) + tasks = task_pool.browse(cr, uid, task_ids, context=context) calendar_id = project.resource_calendar_id.id start_date = project.date_start if not project.date_start: @@ -74,9 +74,10 @@ class wizard_compute_tasks(wizard.interface): time_efficiency = 1.0 resource_id = resource_obj.search(cr, uid, [('user_id', '=', user.id)]) if resource_id: - resource = resource_obj.browse(cr, uid, resource_id, context=context)[0] - leaves = wkcal.compute_leaves(cr, uid, calendar_id or False , resource_id, resource.calendar_id.id) - time_efficiency = resource.time_efficiency +# resource = resource_obj.browse(cr, uid, resource_id, context=context)[0] + resource = resource_obj.read(cr, uid, resource_id, ['calendar_id','time_efficiency'], context=context)[0] + leaves = wkcal.compute_leaves(cr, uid, calendar_id or False , resource_id, resource.get('calendar_id')[0]) + time_efficiency = resource.get('time_efficiency') resources.append(classobj(str(user.name), (Resource,), {'__doc__': user.name, '__name__': user.name, 'vacation': tuple(leaves), @@ -111,7 +112,7 @@ class wizard_compute_tasks(wizard.interface): vacation = tuple(wkcal.compute_leaves(cr, uid, calendar_id)) # Dynamic Creation of tasks i = 0 - for each_task in task_objs: + 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] @@ -135,7 +136,7 @@ class wizard_compute_tasks(wizard.interface): ctx = context.copy() ctx.update({'scheduler': True}) user_id = user_obj.search(cr, uid, [('name', '=', t.booked_resource[0].__name__)]) - task_pool.write(cr, uid, [task_objs[loop_no-1].id], {'date_start': s_date.strftime('%Y-%m-%d %H:%M:%S'), + 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=ctx)