[IMP] project_long_term: clean

bzr revid: mra@tinyerp.com-20100316094140-imcm84fndhikqzqj
This commit is contained in:
mra (Open ERP) 2010-03-16 15:11:40 +05:30
parent 4f7ece5e75
commit 6b1e330846
3 changed files with 20 additions and 19 deletions

View File

@ -179,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
@ -192,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)
@ -278,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}
@ -289,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')})
@ -307,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)
@ -333,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:

View File

@ -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
@ -141,8 +142,8 @@ class wizard_compute_phases(wizard.interface):
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):

View File

@ -62,7 +62,7 @@ class wizard_compute_tasks(wizard.interface):
if task_ids:
task_ids.sort()
tasks = task_pool.browse(cr, uid, task_ids, context=context)
calendar_id = project.resource_calendar_id.id
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")
@ -76,7 +76,7 @@ class wizard_compute_tasks(wizard.interface):
if resource_id:
# 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])
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,