[IMP]:changes in project_long_term,improved view and scheduling of tasks and phases

bzr revid: rvo@tinyerp.co.in-20100226111814-kiapc4zs7parfl8i
This commit is contained in:
Rvo (Open ERP) 2010-02-26 16:48:14 +05:30
parent 512fce7d07
commit fa1c5bbc85
6 changed files with 183 additions and 172 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@ -32,9 +32,10 @@
"init_xml" : [],
"demo_xml" : [#"project_demo.xml"
],
"update_xml": [
"update_xml": [
"project_wizard.xml" ,
"project_view.xml",
"project_wizard.xml"
"project_phase_workflow.xml"
],
'installable': True,
'active': False,

View File

@ -50,7 +50,7 @@ class project_phase(osv.osv):
#iter prev_ids
while prev_ids:
cr.execute('select distinct next_phase_id from project_phase_rel where prv_phase_id in ('+','.join(map(str, prev_ids))+')')
cr.execute('select distinct prv_phase_id from project_phase_rel where next_phase_id in ('+','.join(map(str, prev_ids))+')')
prv_phase_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
if obj_self.id in prv_phase_ids:
return False
@ -61,7 +61,7 @@ class project_phase(osv.osv):
#iter next_ids
while next_ids:
cr.execute('select distinct prv_phase_id from project_phase_rel where next_phase_id in ('+','.join(map(str, next_ids))+')')
cr.execute('select distinct next_phase_id from project_phase_rel where prv_phase_id in ('+','.join(map(str, next_ids))+')')
next_phase_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
if obj_self.id in next_phase_ids:
return False
@ -71,6 +71,13 @@ class project_phase(osv.osv):
next_ids = next_phase_ids
return True
def _check_dates(self, cr, uid, ids):
phase = self.read(cr, uid, ids[0],['date_start','date_end'])
if phase['date_start'] and phase['date_end']:
if phase['date_start'] > phase['date_end']:
return False
return True
_columns = {
'name': fields.char("Phase Name", size=64, required=True),
@ -101,9 +108,100 @@ class project_phase(osv.osv):
}
_order = "name"
# _constraints = [
# (_check_recursion,'Error ! Loops In Phases Not Allowed',['next_phase_ids','previous_phase_ids'])
# ]
_constraints = [
(_check_recursion,'Error ! Loops In Phases Not Allowed',['next_phase_ids','previous_phase_ids']),
(_check_dates, 'Error! Phase start-date must be lower then Phase end-date.', ['date_start', 'date_end'])
]
def onchange_project(self,cr,uid,ids,project):
result = {}
if project:
project_pool = self.pool.get('project.project')
project_id = project_pool.browse(cr,uid,project)
if project_id.date_start:
result['date_start'] = mx.DateTime.strptime(project_id.date_start,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S')
return {'value':result}
return {'value':{'date_start':[]}}
def constraint_date_start(self,cr,uid,phase,date_end,context=None):
# Recursive call for all previous phases if change in date_start < older time
resource_cal_pool = self.pool.get('resource.calendar')
uom_pool = self.pool.get('product.uom')
resource_pool = self.pool.get('resource.resource')
calendar_id = phase.project_id.resource_calendar_id.id
if phase.responsible_id.id:
resource_id = resource_pool.search(cr,uid,[('user_id','=',phase.responsible_id.id)])
calendar_id = resource_pool.browse(cr,uid,resource_id[0]).calendar_id.id
default_uom_id = uom_pool.search(cr,uid,[('name','=','Hour')])[0]
avg_hours = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration,default_uom_id)
work_time = resource_cal_pool.interval_min_get(cr, uid, calendar_id or False, date_end, avg_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,[phase.id],{'date_start':dt_start,'date_end':date_end.strftime('%Y-%m-%d %H:%M:%S')})
def constraint_date_end(self,cr,uid,phase,date_start,context=None):
# Recursive call for all next phases if change in date_end > older time
resource_cal_pool = self.pool.get('resource.calendar')
uom_pool = self.pool.get('product.uom')
resource_pool = self.pool.get('resource.resource')
calendar_id = phase.project_id.resource_calendar_id.id
if phase.responsible_id.id:
resource_id = resource_pool.search(cr,uid,[('user_id','=',phase.responsible_id.id)])
calendar_id = resource_pool.browse(cr,uid,resource_id[0]).calendar_id.id
default_uom_id = uom_pool.search(cr,uid,[('name','=','Hour')])[0]
avg_hours = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration,default_uom_id)
work_time = resource_cal_pool.interval_get(cr, uid, calendar_id or False, date_start, avg_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,[phase.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(project_phase, self).write(cr, uid, ids, vals, context=context)
# if the phase is performed by a resource then its calendar and efficiency also taken
# otherwise the project's working calendar considered
phase = self.browse(cr,uid,ids[0])
resource_cal_pool = self.pool.get('resource.calendar')
resource_pool = self.pool.get('resource.resource')
uom_pool = self.pool.get('product.uom')
resource_id = False
calendar_id = phase.project_id.resource_calendar_id.id
if phase.responsible_id.id:
resource_id = resource_pool.search(cr,uid,[('user_id','=',phase.responsible_id.id)])
calendar_id = resource_pool.browse(cr,uid,resource_id[0]).calendar_id.id
default_uom_id = uom_pool.search(cr,uid,[('name','=','Hour')])[0]
avg_hours = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration,default_uom_id)
# write method changes the date_start and date_end
#for previous and next phases respectively based on valid condition
if vals.get('date_start'):
if vals['date_start'] < phase.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, avg_hours or 0.0,resource_id or False)
vals['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S')
super(project_phase, self).write(cr, uid, ids, vals, context=context)
for prv_phase in phase.previous_phase_ids:
self.constraint_date_start(cr,uid,prv_phase,dt_start)
if vals.get('date_end'):
if vals['date_end'] > phase.date_end:
dt_end = mx.DateTime.strptime(vals['date_end'],'%Y-%m-%d %H:%M:%S')
work_times = resource_cal_pool.interval_min_get(cr, uid, calendar_id or False, dt_end, avg_hours or 0.0,resource_id or False)
vals['date_start'] = work_times[0][0].strftime('%Y-%m-%d %H:%M:%S')
super(project_phase, self).write(cr, uid, ids, vals, context=context)
for next_phase in phase.next_phase_ids:
self.constraint_date_end(cr,uid,next_phase,dt_end)
return super(project_phase, self).write(cr, uid, ids, vals, context=context)
def phase_draft(self, cr, uid, ids,*args):
self.write(cr, uid, ids, {'state': 'draft'})

View File

@ -80,6 +80,7 @@
<page string="Task Detail">
<separator colspan="4" string="Project's Tasks"/>
<field colspan="4" name="task_ids" nolabel="1"/>
<button name="%(wizard_schedule_task)d" string="Schedule Tasks" type="action" icon="gtk-jump-to"/>
</page>
</notebook>

View File

@ -5,11 +5,13 @@
<wizard id="wizard_delegate_task" menu="False" model="project.task" name="project.task.delegate" string="Delegate Task"/>
<wizard id="wizard_attachment_task" model="project.task" name="project.task.attachment" string="All Attachments"/> -->
<wizard id="wizard_compute_phase" menu="False" model="project.phase" name="wizard.compute.phases" string="Compute Phase Scheduling"/>
<menuitem icon="terp-project" id="menu_main" name="Project Management"/>
<!--<menuitem icon="terp-project" id="menu_main" name="Project Management"/>-->
<wizard id="wizard_schedule_task" menu="False" model="project.phase" name="phase.schedule.tasks" string="Schedule Tasks"/>
<menuitem id="base.menu_pm_planning" name="Planning" parent="base.menu_main" sequence="3"/>
<menuitem
action="wizard_compute_phase"
id="menu_wizard_compute_phase"
parent="menu_main"
parent="base.menu_pm_planning"
type="wizard"
sequence="1"/>
</data>

View File

@ -20,6 +20,7 @@
##############################################################################
import compute_phases_date
import schedule_tasks
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -25,17 +25,17 @@ from tools.translate import _
import datetime
from resource.faces import *
from new import classobj
import operator
import project.project_resource as proj
compute_form = """<?xml version="1.0" ?>
<form string="Compute Scheduling of Phases">
<field name="phase_id" colspan="4"/>
<field name="project_id" colspan="4"/>
</form>"""
compute_fields = {
'phase_id': {'string':'Phase', 'type':'many2one', 'relation': 'project.phase', 'required':'True'},
'project_id': {'string':'Project', 'type':'many2one', 'relation': 'project.project'},
}
@ -44,181 +44,89 @@ success_msg = """<?xml version="1.0" ?>
<label string="Phase Scheduling completed successfully."/>
</form>"""
def timeformat_convert(cr, uid, time_string, context={}):
# Function to convert input time string:: 8.5 to output time string 8:30
def phase_schedule(cr,uid,phase,start_date,calendar_id=False):
pool = pooler.get_pool(cr.dbname)
phase_pool = pool.get('project.phase')
resource_pool = pool.get('resource.resource')
uom_pool = pool.get('product.uom')
wktime_cal = []
resource_cal = False
phase_resource = False
if phase:
resource_id = resource_pool.search(cr,uid,[('user_id','=',phase.responsible_id.id)])
if resource_id:
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)
phase_resource = classobj(str(resource_obj.name),(Resource,),{'__doc__':resource_obj.name,'__name__':resource_obj.name,'vacation':tuple(leaves),'efficiency':resource_obj.time_efficiency})
default_uom_id = uom_pool.search(cr,uid,[('name','=','Hour')])[0]
avg_hours = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration,default_uom_id)
duration = str(avg_hours) + 'H'
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
# Creating a new project for each phase
def Project():
start = start_date
minimum_time_unit = 1
resource = phase_resource
# If project has working calendar else the default one would be considered
if calendar_id:
working_days = proj.compute_working_calendar(cr,uid,calendar_id)
vacation = tuple(proj.leaves_resource(cr,uid,calendar_id))
def leaves_resource(cr,uid,id):
# To get the leaves for the resource_ids working on phase
def phase():
effort = duration
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 = []
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
project = BalancedProject(Project)
s_date = project.phase.start.to_datetime()
e_date = project.phase.end.to_datetime()
def resource_list(cr,uid,obj):
# To get the resource_ids working on phase
# According to constraints on date start and date end on phase recalculation done
if phase.constraint_date_start and str(s_date) < phase.constraint_date_start:
start_date = datetime.datetime.strptime(phase.constraint_date_start,'%Y-%m-%d %H:%M:%S')
else:
start_date = s_date
if phase.constraint_date_end and str(e_date) > phase.constraint_date_end:
end_date= datetime.datetime.strptime(phase.constraint_date_end,'%Y-%m-%d %H:%M:%S')
date_start = phase.constraint_date_end[:-3]
else:
end_date = e_date
date_start = end_date
pool = pooler.get_pool(cr.dbname)
resource_pool = pool.get('resource.resource')
resources = obj.resource_ids
resource_objs = []
leaves = []
calendar_id = obj.project_id.resource_calendar_id
for no in range(len(resources)):
resource_id = resource_pool.search(cr,uid,[('id','=',resources[no].resource_id.id)])
if resource_id and calendar_id:
# Getting list of leaves for specific resource
leaves = leaves_resource(cr,uid,resource_id)
# Creating the faces.Resource object with resource specific efficiency and vacation
resource_objs.append(classobj(str(resources[no].resource_id.name),(Resource,),{'__doc__':resources[no].resource_id.name,'__name__':resources[no].resource_id.name,'efficiency':resources[no].useability/100,'vacation':tuple(leaves)}))
return resource_objs
# Writing the dates back
phase_pool.write(cr,uid,[phase.id],{'date_start':start_date.strftime('%Y-%m-%d %H:%M:%S'),'date_end':end_date.strftime('%Y-%m-%d %H:%M:%S')},context={'scheduler':True})
# Recursive calling the next phases till all the phases are scheduled
for phase in phase.next_phase_ids:
if phase.state in ['draft','open','pending']:
phase_schedule(cr,uid,phase,date_start,phase.project_id.resource_calendar_id.id or False)
else:
continue
#
class wizard_compute_phases(wizard.interface):
def _compute_date(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
project_pool = pool.get('project.project')
phase_pool = pool.get('project.phase')
resource_pool = pool.get('resource.resource')
resource_leaves_pool = pool.get('resource.calendar.leaves')
resource_week_pool = pool.get('resource.calendar.week')
avg_hr = 0.0
wktime_cal = []
leaves = []
phase_id = data['form']['phase_id']
phase = phase_pool.browse(cr,uid,phase_id)
calendar_id = phase.project_id.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:
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 = []
hours = []
hr = 0
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'])
# if project mentioned
if data['form']['project_id']:
project_id = project_pool.browse(cr,uid,data['form']['project_id'])
phase_ids = phase_pool.search(cr,uid,[('project_id','=',project_id.id),('state','in',['draft','open','pending']),('previous_phase_ids','=',False)])
# 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
hours.append(week['hour_from'])
hours.append(week['hour_to'])
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 hour in range(len(hours)):
if hour%2 ==0:
hr += float(hours[hour+1]) - float(hours[hour])
avg_hr = hr/len(wktime_cal)
# 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
resource_leave_ids = resource_leaves_pool.search(cr,uid,[('calendar_id','=',calendar_id)])
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()
def phase_schedule(cr,uid,phase,start_date,avg_hour = 0.0):
if phase:
# To get resources and the duration for the phase
resources_list = resource_list(cr,uid,phase)
if not avg_hour:
avg_hour = 8.0
man_days = str(phase.duration * avg_hour) + 'H'
# Creating a new project for each phase
def Project():
start = start_date
minimum_time_unit = 1
# If project has working calendar else the default one would be considered
if wktime_cal:
working_days = wktime_cal
vacation = tuple(leaves)
def phase():
effort = man_days
resource = reduce(operator.or_,resources_list)
project = BalancedProject(Project)
s_date = project.phase.start.to_datetime()
e_date = project.phase.end.to_datetime()
# According to constraints on date start and date end on phase recalculation done
if phase.constraint_date_start and str(s_date) < phase.constraint_date_start:
start_date = phase.constraint_date_start
else:
start_date = s_date
if phase.constraint_date_end and str(e_date) > phase.constraint_date_end:
end_date = phase.constraint_date_end[:-3]
else:
end_date = e_date
# Writing the dates back
phase_pool.write(cr,uid,[phase.id],{'date_start':start_date.strftime('%Y-%m-%d %H:%M:%S'),'date_end':end_date.strftime('%Y-%m-%d %H:%M:%S')})
date_start = end_date
# Recursive calling the next phases till all the phases are scheduled
for phase in phase.next_phase_ids:
phase_schedule(cr,uid,phase,date_start)
# Phase Scheduling starts from here with the call to phase_schedule method
start_dt = datetime.datetime.strftime((datetime.datetime.strptime(phase.project_id.date_start,"%Y-%m-%d")),"%Y-%m-%d %H:%M")
if avg_hr:
phase_schedule(cr,uid,phase,start_dt,avg_hr)
# else all the draft,open,pending states phases taken
else:
phase_schedule(cr,uid,phase,start_dt)
phase_ids = phase_pool.search(cr,uid,[('state','in',['draft','open','pending']),('previous_phase_ids','=',False)])
phase_ids.sort()
phase_objs = phase_pool.browse(cr,uid,phase_ids)
for phase in phase_objs:
start_dt = datetime.datetime.strftime((datetime.datetime.strptime(phase.date_start,"%Y-%m-%d %H:%M:%S")),"%Y-%m-%d %H:%M")
calendar_id = phase.project_id.resource_calendar_id.id
phase_schedule(cr,uid,phase,start_dt,calendar_id or False)
return {}
states = {
'init': {
'actions': [],