From d72306939b1fc1ff30f1f06a2bf9f3e472a28f42 Mon Sep 17 00:00:00 2001 From: "Rvo (Open ERP)" Date: Fri, 26 Feb 2010 19:30:28 +0530 Subject: [PATCH 1/4] [ADD] constraints on constraint date start and constrint date end for phase's start and end bzr revid: rvo@tinyerp.co.in-20100226140028-fdgt9ltb4k7xue2r --- addons/project_long_term/project.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/project_long_term/project.py b/addons/project_long_term/project.py index df21511434f..5bad633e7b0 100644 --- a/addons/project_long_term/project.py +++ b/addons/project_long_term/project.py @@ -78,6 +78,19 @@ class project_phase(osv.osv): return False return True + def _check_constraint_start(self, cr, uid, ids): + phase = self.read(cr, uid, ids[0],['date_start','constraint_date_start']) + if phase['date_start'] and phase['constraint_date_start']: + if phase['date_start'] < phase['constraint_date_start']: + return False + return True + + def _check_constraint_end(self, cr, uid, ids): + phase = self.read(cr, uid, ids[0],['date_end','constraint_date_end']) + if phase['date_end'] and phase['constraint_date_end']: + if phase['date_end'] > phase['constraint_date_end']: + return False + return True _columns = { 'name': fields.char("Phase Name", size=64, required=True), @@ -110,7 +123,10 @@ class project_phase(osv.osv): _order = "name" _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']) + (_check_dates, 'Error! Phase start-date must be lower then Phase end-date.', ['date_start', 'date_end']), + (_check_constraint_start, 'Error! Phase must start-after Constraint Start Date.', ['date_start', 'constraint_date_start']), + (_check_constraint_end, 'Error! Phase must end-before Constraint End Date.', ['date_end', 'constraint_date_end']), + ] def onchange_project(self,cr,uid,ids,project): From 85ff1c55616528d2310460fe39371f049e93e3ca Mon Sep 17 00:00:00 2001 From: "Rvo (Open ERP)" Date: Tue, 2 Mar 2010 18:57:02 +0530 Subject: [PATCH 2/4] [IMP]:removed everything related to resource & scheduling from project to project_long_term module bzr revid: rvo@tinyerp.co.in-20100302132702-xm7yv8ura1eqzdzc --- addons/project/project.py | 100 +--------- addons/project/project_view.xml | 5 +- addons/project/project_wizard.xml | 10 - addons/project/wizard/__init__.py | 2 - addons/project_long_term/project.py | 171 ++++++++++++++---- addons/project_long_term/project_demo.xml | 40 ++-- addons/project_long_term/project_wizard.xml | 10 +- addons/project_long_term/wizard/__init__.py | 2 + .../wizard/compute_phases_date.py | 41 ++--- .../wizard/compute_tasks_date.py | 150 +++++++++++++++ .../wizard/project_resource.py | 81 +++++++++ .../wizard/schedule_tasks.py | 38 ++-- addons/resource/resource.py | 45 +++-- 13 files changed, 459 insertions(+), 236 deletions(-) create mode 100644 addons/project_long_term/wizard/compute_tasks_date.py create mode 100644 addons/project_long_term/wizard/project_resource.py diff --git a/addons/project/project.py b/addons/project/project.py index a0589ac76eb..40fadc7ae45 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -256,25 +256,8 @@ 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, project, user_id = False,planned=0.0, effective=0.0,date_start=None,occupation_rate=0.0): - result = {} - 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} + def onchange_planned(self, cr, uid, ids, planned = 0.0, effective = 0.0): + return {'value':{'remaining_hours' : planned - effective}} def _default_project(self, cr, uid, context={}): if 'project_id' in context and context['project_id']: @@ -315,7 +298,6 @@ class task(osv.osv): 'parent_ids': fields.many2many('project.task', 'project_task_parent_rel', 'task_id', 'parent_id', 'Parent Tasks'), 'child_ids': fields.many2many('project.task', 'project_task_parent_rel', 'parent_id', 'task_id', 'Delegated Tasks'), 'notes': fields.text('Notes'), - 'occupation_rate': fields.float('Occupation Rate', help='The occupation rate fields indicates how much of his time a user is working on a task. A 100% occupation rate means the user works full time on the tasks. The ending date of a task is computed like this: Starting Date + Duration / Occupation Rate.'), 'planned_hours': fields.float('Planned Hours', required=True, help='Estimated time to do the task, usually set by the project manager when the task is in draft state.'), 'effective_hours': fields.function(_hours_get, method=True, string='Hours Spent', multi='hours', store=True, help="Computed using the sum of the task work done."), 'remaining_hours': fields.float('Remaining Hours', digits=(16,4), help="Total remaining time, can be re-estimated periodically by the assignee of the task."), @@ -339,7 +321,6 @@ class task(osv.osv): 'active': lambda *a: True, 'date_start': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), 'project_id': _default_project, - 'occupation_rate':lambda *a: '1', 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'project.task', context=c) } _order = "sequence, priority, date_start, id" @@ -479,83 +460,6 @@ 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_old(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): diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index 4895d84e01c..63584bea532 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -247,7 +247,7 @@ name="planned_hours" widget="float_time" attrs="{'readonly':[('state','!=','draft')]}" - on_change="onchange_planned(project_id,user_id,planned_hours,effective_hours,date_start,occupation_rate)"/> + on_change="onchange_planned(planned_hours, effective_hours)"/>