From eaa543f198201f31b03615c9ea958658b39bb6b0 Mon Sep 17 00:00:00 2001 From: Husen Daudi Date: Thu, 4 Dec 2008 12:17:26 +0530 Subject: [PATCH] bug fixed for task remaining hours lp bug: https://launchpad.net/bugs/304410 fixed bzr revid: hda@tinyerp.com-20081204064726-qlw3l0x291jtnql2 --- addons/project/project.py | 46 ++++++++++++++++++++++++++------- addons/project/project_view.xml | 34 ++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index c2337da7053..4d9261f2ea0 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -247,15 +247,6 @@ class task(osv.osv): # ('remaining_hours', 'CHECK (remaining_hours>=0)', 'Please increase and review remaining hours ! It can not be smaller than 0.'), #] - def _button_dummy(self, cr, uid, ids, context={}): - tot_work=0 - for obj in self.browse(cr,uid,ids): - for work in obj.work_ids: - tot_work+=work.hours - final_val = obj.planned_hours - tot_work - self.write(cr,uid,ids[0],{'remaining_hours':final_val}) - return True - def copy(self, cr, uid, id, default={},context={}): default = default or {} default['work_ids'] = [] @@ -417,8 +408,45 @@ class project_work(osv.osv): 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S') } _order = "date desc" + def create(self, cr, uid, vals, *args, **kwargs): + if 'task_id' in vals: + cr.execute('update project_task set remaining_hours=remaining_hours+%.2f where id=%d', (-vals.get('hours',0.0), vals['task_id'])) + return super(project_work,self).create(cr, uid, vals, *args, **kwargs) + def write(self, cr, uid, ids,vals,context={}): + for work in self.browse(cr, uid, ids, context): + cr.execute('update project_task set remaining_hours=remaining_hours+%.2f+(%.2f) where id=%d', (-vals.get('hours',0.0), work.hours, work.task_id.id)) + return super(project_work,self).write(cr, uid, ids, vals, context) + + def unlink(self, cr, uid, ids, *args, **kwargs): + for work in self.browse(cr, uid, ids): + cr.execute('update project_task set remaining_hours=remaining_hours+%.2f where id=%d', (work.hours, work.task_id.id)) + return super(project_work,self).unlink(cr, uid, ids,*args, **kwargs) project_work() +class config_compute_remaining(osv.osv_memory): + _name='config.compute.remaining' + def _get_remaining(self,cr, uid, ctx): + if 'active_id' in ctx: + return self.pool.get('project.task').browse(cr,uid,ctx['active_id']).remaining_hours + return False + + _columns = { + 'remaining_hours' : fields.float('Remaining Hours', digits=(16,2), help="Total remaining time, can be re-estimated periodically by the assignee of the task."), + } + + _defaults = { + 'remaining_hours': _get_remaining + } + + def compute_hours(self, cr, uid, ids, context=None): + if 'active_id' in context: + remaining_hrs=self.browse(cr,uid,ids)[0].remaining_hours + self.pool.get('project.task').write(cr,uid,context['active_id'],{'remaining_hours':remaining_hrs}) + return { + 'type': 'ir.actions.act_window_close', + } +config_compute_remaining() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index b2d31694d57..b7ec8362408 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -197,6 +197,34 @@ id="menu_open_view_my_project_open" parent="project.menu_all_project"/> + + + + Compute Remaining Hours + config.compute.remaining + form + +
+ + + + +