diff options
| author | mra (Open ERP) <mra@tinyerp.com> | 2010-03-16 16:09:34 +0530 |
|---|---|---|
| committer | mra (Open ERP) <mra@tinyerp.com> | 2010-03-16 16:09:34 +0530 |
| commit | 60f678f6e51d503c824fa94cdad59b7d1d926e6f (patch) | |
| tree | 6ce0d33e800edd056dad6c51efd619a54be680e8 /addons/project_long_term | |
| parent | 60e079dbd726094b5f0925609493b6e35e38e09a (diff) | |
| parent | 4771021d88484281eb63e988bb3c12dc6612f688 (diff) | |
[IMP] project_long_term: Clean code
bzr revid: mra@tinyerp.com-20100316103934-qvjag9zu1ue7zk2u
Diffstat (limited to 'addons/project_long_term')
| -rw-r--r-- | addons/project_long_term/project_long_term.py | 36 | ||||
| -rw-r--r-- | addons/project_long_term/wizard/compute_phases_date.py | 11 | ||||
| -rw-r--r-- | addons/project_long_term/wizard/compute_tasks_date.py | 15 |
3 files changed, 34 insertions, 28 deletions
diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 48129f40bb8..684fbcc776a 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] @@ -175,7 +179,7 @@ class project_phase(osv.osv): # Consider calendar and efficiency if the phase is performed by a resource # otherwise consider the project's working calendar phase = self.browse(cr, uid, ids[0], context=context) - calendar_id = phase.project_id.resource_calendar_id.id + 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 @@ -188,13 +192,13 @@ class project_phase(osv.osv): # for previous and next phases respectively based on valid condition if vals.get('date_start', False) and vals['date_start'] < phase.date_start: dt_start = mx.DateTime.strptime(vals['date_start'],'%Y-%m-%d %H:%M:%S') - work_times = resource_calendar_obj.interval_get(cr, uid, calendar_id or False, dt_start, avg_hours or 0.0, resource_id and resource_id[0] or False) + work_times = resource_calendar_obj.interval_get(cr, uid, calendar_id, dt_start, avg_hours or 0.0, resource_id and resource_id[0] or False) vals['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S') for prv_phase in phase.previous_phase_ids: self._check_date_start(cr, uid, prv_phase, dt_start, context=context) if vals.get('date_end', False) and vals['date_end'] > phase.date_end: dt_end = mx.DateTime.strptime(vals['date_end'],'%Y-%m-%d %H:%M:%S') - work_times = resource_calendar_obj.interval_min_get(cr, uid, calendar_id or False, dt_end, avg_hours or 0.0, resource_id and resource_id[0] or False) + work_times = resource_calendar_obj.interval_min_get(cr, uid, calendar_id, dt_end, avg_hours or 0.0, resource_id and resource_id[0] or False) vals['date_start'] = work_times[0][0].strftime('%Y-%m-%d %H:%M:%S') for next_phase in phase.next_phase_ids: self._check_date_end(cr, uid, next_phase, dt_end, context=context) @@ -274,7 +278,7 @@ class task(osv.osv): hrs = planned / (float(occupation_rate) * resource.time_efficiency) if resource.calendar_id.id: calendar_id = resource.calendar_id.id - work_times = resource_calendar.interval_get(cr, uid, calendar_id or False, dt_start, hrs or 0.0, resource.id or False) + work_times = resource_calendar.interval_get(cr, uid, calendar_id, dt_start, hrs or 0.0, resource.id or False) result['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S') result['remaining_hours'] = planned - effective return {'value' : result} @@ -285,15 +289,15 @@ class task(osv.osv): """ resource_calendar_obj = self.pool.get('resource.calendar') resource_obj = self.pool.get('resource.resource') - calendar_id = task.project_id.resource_calendar_id.id + calendar_id = task.project_id.resource_calendar_id and task.project_id.resource_calendar_id.id or False hours = task.planned_hours / task.occupation_rate resource_id = resource_obj.search(cr, uid, [('user_id', '=', task.user_id.id)], context=context) if resource_id: resource = resource_obj.browse(cr, uid, resource_id[0], context=context) if resource.calendar_id.id: - calendar_id = resource.calendar_id.id + calendar_id = resource.calendar_id and resource.calendar_id.id or False hours = task.planned_hours / (float(task.occupation_rate) * resource.time_efficiency) - work_times = resource_calendar_obj.interval_min_get(cr, uid, calendar_id or False, date_end, hours or 0.0, resource_id or False) + work_times = resource_calendar_obj.interval_min_get(cr, uid, calendar_id, date_end, hours or 0.0, resource_id or False) dt_start = work_times[0][0].strftime('%Y-%m-%d %H:%M:%S') self.write(cr, uid, [task.id], {'date_start' : dt_start,'date_end' : date_end.strftime('%Y-%m-%d %H:%M:%S')}) @@ -303,15 +307,15 @@ class task(osv.osv): """ resource_calendar_obj = self.pool.get('resource.calendar') resource_obj = self.pool.get('resource.resource') - calendar_id = task.project_id.resource_calendar_id.id + calendar_id = task.project_id.resource_calendar_id and task.project_id.resource_calendar_id.id or False hours = task.planned_hours / task.occupation_rate resource_id = resource_obj.search(cr,uid,[('user_id', '=', task.user_id.id)], context=context) if resource_id: resource = resource_obj.browse(cr, uid, resource_id[0], context=context) if resource.calendar_id.id: - calendar_id = resource.calendar_id.id + calendar_id = resource.calendar_id and resource.calendar_id.id or False hours = task.planned_hours / (float(task.occupation_rate) * resource.time_efficiency) - work_times = resource_calendar_obj.interval_get(cr, uid, calendar_id or False, date_start, hours or 0.0, resource.id or False) + work_times = resource_calendar_obj.interval_get(cr, uid, calendar_id, date_start, hours or 0.0, resource.id or False) dt_end = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S') self.write(cr, uid, [task.id], {'date_start': date_start.strftime('%Y-%m-%d %H:%M:%S'),'date_end' : dt_end}, context=context) @@ -329,27 +333,27 @@ class task(osv.osv): if isinstance(ids, list): task_id = ids[0] task_rec = self.browse(cr, uid, task_id, context=context) - calendar_id = task_rec.project_id.resource_calendar_id.id + calendar_id = task_rec.project_id.resource_calendar_id and task_rec.project_id.resource_calendar_id.id or False hrs = task_rec.planned_hours / task_rec.occupation_rate resource_id = resource_obj.search(cr, uid, [('user_id', '=', task_rec.user_id.id)], context=context) if resource_id: resource = resource_obj.browse(cr, uid, resource_id[0], context=context) if resource.calendar_id.id: - calendar_id = resource.calendar_id.id + calendar_id = resource.calendar_id and resource.calendar_id.id or False hrs = task_rec.planned_hours / (float(task_rec.occupation_rate) * resource.time_efficiency) # Change the date_start and date_end # for previous and next tasks respectively based on valid condition if vals.get('date_start', False) and vals['date_start'] < task_rec.date_start: dt_start = mx.DateTime.strptime(vals['date_start'], '%Y-%m-%d %H:%M:%S') - work_times = resource_calendar_obj.interval_get(cr, uid, calendar_id or False, dt_start, hrs or 0.0, resource.id or False) + work_times = resource_calendar_obj.interval_get(cr, uid, calendar_id, dt_start, hrs or 0.0, resource.id or False) vals['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S') super(task, self).write(cr, uid, ids, vals, context=context) for prv_task in task_rec.parent_ids: self._check_date_start(cr, uid, prv_task, dt_start) if vals.get('date_end', False) and vals['date_end'] > task_rec.date_end: dt_end = mx.DateTime.strptime(vals['date_end'], '%Y-%m-%d %H:%M:%S') - work_times = resource_calendar_obj.interval_min_get(cr, uid, calendar_id or False, dt_end, hrs or 0.0, resource.id or False) + work_times = resource_calendar_obj.interval_min_get(cr, uid, calendar_id, dt_end, hrs or 0.0, resource.id or False) vals['date_start'] = work_times[0][0].strftime('%Y-%m-%d %H:%M:%S') super(task, self).write(cr, uid, ids, vals, context=context) for next_task in task_rec.child_ids: diff --git a/addons/project_long_term/wizard/compute_phases_date.py b/addons/project_long_term/wizard/compute_phases_date.py index f684871e636..f7e49f23247 100644 --- a/addons/project_long_term/wizard/compute_phases_date.py +++ b/addons/project_long_term/wizard/compute_phases_date.py @@ -113,7 +113,8 @@ class wizard_compute_phases(wizard.interface): # Recursive call till all the next phases scheduled for phase in phase.next_phase_ids: if phase.state in ['draft','open','pending']: - self._phase_schedule(cr, uid, phase, date_start, phase.project_id.resource_calendar_id.id or False, context=context) + id_cal = phase.project_id.resource_calendar_id and phase.project_id.resource_calendar_id.id or False + self._phase_schedule(cr, uid, phase, date_start, id_cal, context=context) else: continue @@ -135,14 +136,14 @@ 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") start_dt = 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 - self._phase_schedule(cr, uid, phase, start_dt, calendar_id or False, context=context) + calendar_id = phase.project_id.resource_calendar_id and phase.project_id.resource_calendar_id.id or False + self._phase_schedule(cr, uid, phase, start_dt, calendar_id, context=context) return {} def _open_phases_list(self, cr, uid, data, context): diff --git a/addons/project_long_term/wizard/compute_tasks_date.py b/addons/project_long_term/wizard/compute_tasks_date.py index 1187980057b..17a2b90b50b 100644 --- a/addons/project_long_term/wizard/compute_tasks_date.py +++ b/addons/project_long_term/wizard/compute_tasks_date.py @@ -61,8 +61,8 @@ class wizard_compute_tasks(wizard.interface): ]) if task_ids: task_ids.sort() - task_objs = task_pool.browse(cr, uid, task_ids, context=context) - calendar_id = project.resource_calendar_id.id + tasks = task_pool.browse(cr, uid, task_ids, context=context) + calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False start_date = project.date_start if not project.date_start: start_date = datetime.datetime.now().strftime("%Y-%m-%d") @@ -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 , 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) |
