Project management improvements

bzr revid: hda@tinyerp.com-20100226132006-lomo55f42zug2o1n
This commit is contained in:
HDA (OpenERP)
2010-02-26 18:50:06 +05:30
16 changed files with 783 additions and 389 deletions
+93 -10
View File
@@ -256,17 +256,23 @@ class task(osv.osv):
res[task.id]['delay_hours'] = res[task.id]['total_hours'] - task.planned_hours
return res
def onchange_planned(self, cr, uid, ids, planned=0.0, effective=0.0, date_start=None,occupation_rate=0.0):
def onchange_planned(self, cr, uid, ids, project, user_id = False,planned=0.0, effective=0.0,date_start=None,occupation_rate=0.0):
result = {}
for res in self.browse(cr, uid, ids):
if date_start and planned:
resource_id = self.pool.get('resource.resource').search(cr,uid,[('user_id','=',res.user_id.id)])
if resource_id:
resource_obj = self.pool.get('resource.resource').browse(cr,uid,resource_id)[0]
d = mx.DateTime.strptime(date_start,'%Y-%m-%d %H:%M:%S')
hrs = (planned)/(occupation_rate)
work_times = self.pool.get('resource.calendar').interval_get(cr, uid, resource_obj.calendar_id.id or False, d, hrs or 0.0, resource_obj.id)
result['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S')
if date_start:
resource_pool = self.pool.get('resource.resource')
project_pool = self.pool.get('project.project')
resource_calendar = self.pool.get('resource.calendar')
dt_start = mx.DateTime.strptime(date_start,'%Y-%m-%d %H:%M:%S')
resource_id = resource_pool.search(cr,uid,[('user_id','=',user_id)])
if resource_id:
resource_obj = resource_pool.browse(cr,uid,resource_id)[0]
hrs = planned/(float(occupation_rate) * resource_obj.time_efficiency)
calendar_id = resource_obj.calendar_id.id
else:
hrs = float(planned / occupation_rate)
calendar_id = project_pool.browse(cr,uid,project).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)
result['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S')
result['remaining_hours'] = planned-effective
return {'value':result}
@@ -473,6 +479,83 @@ class task(osv.osv):
self.write(cr, uid, typ.id, {'type': index and types[index-1] or False})
return True
def constraint_date_start(self,cr,uid,task,date_end,context=None):
# Recursive call for all previous tasks if change in date_start < older time
resource_cal_pool = self.pool.get('resource.calendar')
resource_pool = self.pool.get('resource.resource')
calendar_id = task.project_id.resource_calendar_id.id
hours = task.remaining_hours / task.occupation_rate
resource_id = resource_pool.search(cr,uid,[('user_id','=',task.user_id.id)])
if resource_id:
resource_obj = resource_pool.browse(cr,uid,resource_id[0])
calendar_id = resource_obj.calendar_id.id
hours = task.planned_hours/(float(task.occupation_rate) * resource_obj.time_efficiency)
work_time = resource_cal_pool.interval_min_get(cr, uid, calendar_id or False, date_end, hours or 0.0,resource_id or False)
dt_start = work_time[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')})
def constraint_date_end(self,cr,uid,task,date_start,context=None):
# Recursive call for all next tasks if change in date_end > older time
resource_cal_pool = self.pool.get('resource.calendar')
resource_pool = self.pool.get('resource.resource')
calendar_id = task.project_id.resource_calendar_id.id
hours = task.remaining_hours / task.occupation_rate
resource_id = resource_pool.search(cr,uid,[('user_id','=',task.user_id.id)])
if resource_id:
resource_obj = resource_pool.browse(cr,uid,resource_id[0])
calendar_id = resource_obj.calendar_id.id
hours = task.planned_hours/(float(task.occupation_rate) * resource_obj.time_efficiency)
work_time = resource_cal_pool.interval_get(cr, uid, calendar_id or False, date_start, hours or 0.0,resource_id or False)
dt_end = work_time[-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})
def write(self, cr, uid, ids, vals,context=None):
if not context:
context = {}
if context.get('scheduler',False):
return super(task, self).write(cr, uid, ids, vals, context=context)
# if the task is performed by a resource then its calendar and efficiency also taken
# otherwise the project's working calendar considered
tasks = self.browse(cr,uid,ids[0])
resource_cal_pool = self.pool.get('resource.calendar')
resource_pool = self.pool.get('resource.resource')
calendar_id = tasks.project_id.resource_calendar_id.id
hrs = tasks.remaining_hours / tasks.occupation_rate
resource_id = resource_pool.search(cr,uid,[('user_id','=',tasks.user_id.id)])
if resource_id:
resource_obj = resource_pool.browse(cr,uid,resource_id[0])
calendar_id = resource_obj.calendar_id.id
hrs = tasks.planned_hours/(float(tasks.occupation_rate) * resource_obj.time_efficiency)
# write method changes the date_start and date_end
# for previous and next tasks respectively based on valid condition
if vals.get('date_start'):
if vals['date_start'] < tasks.date_start:
dt_start = mx.DateTime.strptime(vals['date_start'],'%Y-%m-%d %H:%M:%S')
work_times = resource_cal_pool.interval_get(cr, uid, calendar_id or False, 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 tasks.parent_ids:
self.constraint_date_start(cr,uid,prv_task,dt_start)
if vals.get('date_end'):
if vals['date_end'] > tasks.date_end:
dt_end = mx.DateTime.strptime(vals['date_end'],'%Y-%m-%d %H:%M:%S')
hrs = tasks.remaining_hours / tasks.occupation_rate
work_times = resource_cal_pool.interval_min_get(cr, uid, calendar_id or False, 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 tasks.child_ids:
self.constraint_date_end(cr,uid,next_task,dt_end)
return super(task, self).write(cr, uid, ids, vals, context=context)
task()
class project_work(osv.osv):
+81
View File
@@ -0,0 +1,81 @@
import pooler
import datetime
def timeformat_convert(cr, uid, time_string, context={}):
# Function to convert input time string:: 8.5 to output time string 8:30
split_list = str(time_string).split('.')
hour_part = split_list[0]
mins_part = split_list[1]
round_mins = int(round(float(mins_part) * 60,-2))
converted_string = hour_part + ':' + str(round_mins)[0:2]
return converted_string
def leaves_resource(cr,uid,calendar_id,resource_id=False,resource_calendar=False):
# To get the leaves for the resource_ids working on phase
pool = pooler.get_pool(cr.dbname)
resource_leaves_pool = pool.get('resource.calendar.leaves')
leaves = []
if resource_id:
resource_leave_ids = resource_leaves_pool.search(cr,uid,['|',('calendar_id','=',calendar_id),('calendar_id','=',resource_calendar),('resource_id','=',resource_id)])
else:
resource_leave_ids = resource_leaves_pool.search(cr,uid,[('calendar_id','=',calendar_id),('resource_id','=',False)])
res_leaves = resource_leaves_pool.read(cr,uid,resource_leave_ids,['date_from','date_to'])
for leave in range(len(res_leaves)):
dt_start = datetime.datetime.strptime(res_leaves[leave]['date_from'],'%Y-%m-%d %H:%M:%S')
dt_end = datetime.datetime.strptime(res_leaves[leave]['date_to'],'%Y-%m-%d %H:%M:%S')
no = dt_end - dt_start
[leaves.append((dt_start + datetime.timedelta(days=x)).strftime('%Y-%m-%d')) for x in range(int(no.days + 1))]
leaves.sort()
return leaves
def compute_working_calendar(cr,uid,calendar_id):
# To change the format of working calendar to bring it into 'faces' format
pool = pooler.get_pool(cr.dbname)
resource_week_pool = pool.get('resource.calendar.week')
time_range = "8:00-8:00"
non_working = ""
wk = {"0":"mon","1":"tue","2":"wed","3":"thu","4":"fri","5":"sat","6":"sun"}
wk_days = {}
wk_time = {}
wktime_list = []
wktime_cal = []
week_ids = resource_week_pool.search(cr,uid,[('calendar_id','=',calendar_id)])
week_obj = resource_week_pool.read(cr,uid,week_ids,['dayofweek','hour_from','hour_to'])
# Converting time formats into appropriate format required
# and creating a list like [('mon', '8:00-12:00'), ('mon', '13:00-18:00')]
for week in week_obj:
res_str = ""
if wk.has_key(week['dayofweek']):
day = wk[week['dayofweek']]
wk_days[week['dayofweek']] = wk[week['dayofweek']]
hour_from_str = timeformat_convert(cr,uid,week['hour_from'])
hour_to_str = timeformat_convert(cr,uid,week['hour_to'])
res_str = hour_from_str + '-' + hour_to_str
wktime_list.append((day,res_str))
# Converting it to format like [('mon', '8:00-12:00', '13:00-18:00')]
for item in wktime_list:
if wk_time.has_key(item[0]):
wk_time[item[0]].append(item[1])
else:
wk_time[item[0]] = [item[0]]
wk_time[item[0]].append(item[1])
for k,v in wk_time.items():
wktime_cal.append(tuple(v))
# For non working days adding [('tue,wed,fri,sat,sun', '8:00-8:00')]
for k,v in wk_days.items():
if wk.has_key(k):
wk.pop(k)
for v in wk.itervalues():
non_working += v + ','
if non_working:
wktime_cal.append((non_working[:-1],time_range))
return wktime_cal
+1 -1
View File
@@ -247,7 +247,7 @@
name="planned_hours"
widget="float_time"
attrs="{'readonly':[('state','!=','draft')]}"
on_change="onchange_planned(planned_hours,effective_hours,date_start,occupation_rate)"/>
on_change="onchange_planned(project_id,user_id,planned_hours,effective_hours,date_start,occupation_rate)"/>
<field name="remaining_hours" select="2" widget="float_time" attrs="{'readonly':[('state','!=','draft')]}" colspan="2"/>
<button name="%(action_config_compute_remaining)d" string="Review" type="action" colspan="1" target="new" states="open,pending" icon="gtk-edit"/>
</group>
+24 -116
View File
@@ -26,12 +26,11 @@ import datetime
from resource.faces import *
from new import classobj
import operator
import time
import project.project_resource as proj
compute_form = """<?xml version="1.0" ?>
<form string="Compute Scheduling of Tasks">
<field name="project_id" colspan="4"/>
<field name= "date_from" colspan="4"/>
</form>"""
success_msg = """<?xml version="1.0" ?>
@@ -41,132 +40,39 @@ success_msg = """<?xml version="1.0" ?>
compute_fields = {
'project_id': {'string':'Project', 'type':'many2one', 'relation': 'project.project', 'required':'True'},
'date_from': {'string':"Start date",'type':'datetime','required':'True' ,'default': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')},
}
def timeformat_convert(cr, uid, time_string, context={}):
# Function to convert input time string:: 8.5 to output time string 8:30
split_list = str(time_string).split('.')
hour_part = split_list[0]
mins_part = split_list[1]
round_mins = int(round(float(mins_part) * 60,-2))
converted_string = hour_part + ':' + str(round_mins)[0:2]
return converted_string
def leaves_resource(cr,uid,id):
# To get the leaves for the members working on project
pool = pooler.get_pool(cr.dbname)
resource_leaves_pool = pool.get('resource.calendar.leaves')
resource_leave_ids = resource_leaves_pool.search(cr,uid,[('resource_id','=',id)])
leaves = []
if resource_leave_ids:
res_leaves = resource_leaves_pool.read(cr,uid,resource_leave_ids,['date_from','date_to'])
for leave in range(len(res_leaves)):
dt_start = datetime.datetime.strptime(res_leaves[leave]['date_from'],'%Y-%m-%d %H:%M:%S')
dt_end = datetime.datetime.strptime(res_leaves[leave]['date_to'],'%Y-%m-%d %H:%M:%S')
no = dt_end - dt_start
leave_days = no.days + 1
[leaves.append((dt_start + datetime.timedelta(days=x)).strftime('%Y-%m-%d')) for x in range(int(leave_days))]
leaves.sort()
return leaves
class wizard_compute_tasks(wizard.interface):
def _compute_date(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
project_pool = pool.get('project.project')
task_pool = pool.get('project.task')
resource_pool = pool.get('resource.resource')
resource_leaves_pool = pool.get('resource.calendar.leaves')
resource_week_pool = pool.get('resource.calendar.week')
user_pool = pool.get('res.users')
project_id = data['form']['project_id']
project = project_pool.browse(cr,uid,project_id)
task_ids = task_pool.search(cr,uid,[('project_id','=',project_id)])
task_ids = task_pool.search(cr,uid,[('project_id','=',project_id),('state','in',['draft','open','pending'])])
if task_ids:
wktime_cal = []
leaves = []
task_ids.sort()
task_obj = task_pool.browse(cr,uid,task_ids)
task_1 = task_obj[0]
date_start = datetime.datetime.strftime(datetime.datetime.strptime(data['form']['date_from'],"%Y-%m-%d %H:%M:%S"),"%Y-%m-%d %H:%M")
calendar_id = project.resource_calendar_id.id
# If project has a working calendar then that would be used otherwise
# the default faces calendar would be used
if calendar_id:
resource_leave_ids = resource_leaves_pool.search(cr,uid,[('calendar_id','=',calendar_id)])
time_range = "8:00-8:00"
non_working = ""
wk = {"0":"mon","1":"tue","2":"wed","3":"thu","4":"fri","5":"sat","6":"sun"}
wk_days = {}
wk_time = {}
wktime_list = []
week_ids = resource_week_pool.search(cr,uid,[('calendar_id','=',calendar_id)])
week_obj = resource_week_pool.read(cr,uid,week_ids,['dayofweek','hour_from','hour_to'])
# Converting time formats into appropriate format required
# and creating a list like [('mon', '8:00-12:00'), ('mon', '13:00-18:00')]
for week in week_obj:
res_str = ""
if wk.has_key(week['dayofweek']):
day = wk[week['dayofweek']]
wk_days[week['dayofweek']] = wk[week['dayofweek']]
hour_from_str = timeformat_convert(cr,uid,week['hour_from'])
hour_to_str = timeformat_convert(cr,uid,week['hour_to'])
res_str = hour_from_str + '-' + hour_to_str
wktime_list.append((day,res_str))
# Converting it to format like [('mon', '8:00-12:00', '13:00-18:00')]
for item in wktime_list:
if wk_time.has_key(item[0]):
wk_time[item[0]].append(item[1])
else:
wk_time[item[0]] = [item[0]]
wk_time[item[0]].append(item[1])
for k,v in wk_time.items():
wktime_cal.append(tuple(v))
# For non working days adding [('tue,wed,fri,sat,sun', '8:00-8:00')]
for k,v in wk_days.items():
if wk.has_key(k):
wk.pop(k)
for v in wk.itervalues():
non_working += v + ','
if non_working:
wktime_cal.append((non_working[:-1],time_range))
# If project working calendar has any leaves
if resource_leave_ids:
res_leaves = resource_leaves_pool.read(cr,uid,resource_leave_ids,['date_from','date_to'])
for leave in range(len(res_leaves)):
dt_start = datetime.datetime.strptime(res_leaves[leave]['date_from'],'%Y-%m-%d %H:%M:%S')
dt_end = datetime.datetime.strptime(res_leaves[leave]['date_to'],'%Y-%m-%d %H:%M:%S')
no = dt_end - dt_start
leave_days = no.days + 1
[leaves.append((dt_start + datetime.timedelta(days=x)).strftime('%Y-%m-%d')) for x in range(int(leave_days))]
leaves.sort()
start_date = project.date_start
if not project.date_start:
start_date = datetime.datetime.now().strftime("%Y-%m-%d")
date_start = datetime.datetime.strftime(datetime.datetime.strptime(start_date,"%Y-%m-%d"),"%Y-%m-%d %H:%M")
# To create resources which are the Project Members
resource = project.members
resource_objs = []
for no in range(len(resource)):
for resource in project.members:
leaves = []
resource_eff = 1.00
resource_id = resource_pool.search(cr,uid,[('user_id','=',resource[no].id)])
resource_id = resource_pool.search(cr,uid,[('user_id','=',resource.id)])
if resource_id:
# Getting the efficiency for specific resource
resource_eff = resource_pool.browse(cr,uid,resource_id)[0].time_efficiency
resource_obj = resource_pool.browse(cr,uid,resource_id)[0]
leaves = proj.leaves_resource(cr,uid,calendar_id or False ,resource_id,resource_obj.calendar_id.id)
resource_objs.append(classobj(str(resource.name),(Resource,),{'__doc__':resource.name,'__name__':resource.name,'vacation':tuple(leaves),'efficiency':resource_obj.time_efficiency}))
# Getting list of leaves for specific resource
if wktime_cal:
leaves = leaves_resource(cr,uid,resource_id)
resource_objs.append(classobj(str(resource[no].name),(Resource,),{'__doc__':resource[no].name,'__name__':resource[no].name,'vacation':tuple(leaves),'efficiency':resource_eff}))
priority_dict = {'0':1000,'1':800,'2':500,'3':300,'4':100}
# To create dynamic no of tasks with the resource specified
@@ -191,22 +97,25 @@ class wizard_compute_tasks(wizard.interface):
minimum_time_unit = 1
# If project has calendar
if wktime_cal:
working_days = wktime_cal
vacation = tuple(leaves)
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
for i in range(len(task_obj)):
hours = str(task_obj[i].remaining_hours / task_obj[i].occupation_rate)+ 'H'
if task_obj[i].priority in priority_dict.keys():
priorty = priority_dict[task_obj[i].priority]
if task_obj[i].user_id:
i = 0
for each_task in task_obj:
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__ == task_obj[i].user_id.name:
if resource_object.__name__ == each_task.user_id.name:
task = tasks_resource(i,hours,priorty,resource_object)
else:
task = tasks_resource(i,hours,priorty)
i += 1
# Writing back the dates
project = BalancedProject(Project)
loop_no = 0
for t in project:
@@ -216,9 +125,8 @@ class wizard_compute_tasks(wizard.interface):
project_pool.write(cr,uid,[project_id],{'date':e_date})
else:
user_id = user_pool.search(cr,uid,[('name','=',t.booked_resource[0].__name__)])
task_pool.write(cr,uid,[task_obj[loop_no-1].id],{'date_start':s_date,'date_deadline':e_date,'user_id':user_id[0]})
task_pool.write(cr,uid,[task_obj[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]})
loop_no +=1
return {}
states = {