bug fixed for task remaining hours

lp bug: https://launchpad.net/bugs/304410 fixed

bzr revid: hda@tinyerp.com-20081204064726-qlw3l0x291jtnql2
This commit is contained in:
Husen Daudi 2008-12-04 12:17:26 +05:30
parent 449d189626
commit eaa543f198
2 changed files with 69 additions and 11 deletions

View File

@ -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:

View File

@ -197,6 +197,34 @@
id="menu_open_view_my_project_open"
parent="project.menu_all_project"/>
<!-- Wizard for compute remaining hours -->
<record id="view_config_compute_remaining" model="ir.ui.view">
<field name="name">Compute Remaining Hours </field>
<field name="model">config.compute.remaining</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Remaining Hours">
<separator colspan="4" string="Change Remaining Hours"/>
<newline/>
<field name="remaining_hours" widget="float_time"/>
<group col="4" colspan="4">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-ok" name="compute_hours" string="Compute" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_config_compute_remaining" model="ir.actions.act_window">
<field name="name">Compute Remaining Hours</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">config.compute.remaining</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- Task -->
<record id="view_task_form2" model="ir.ui.view">
<field name="name">project.task.form</field>
@ -220,8 +248,10 @@
widget="float_time"
on_change="onchange_planned(planned_hours,effective_hours)"/>
<field name="delay_hours" widget="float_time"/>
<field name="remaining_hours" select="2" widget="float_time" attrs="{'readonly':[('state','!=','draft')]}" colspan="1"/>
<button name="_button_dummy" string="Compute" type="object" colspan="1"/>
<group col="3" colspan="2">
<field name="remaining_hours" select="2" widget="float_time" attrs="{'readonly':[('state','!=','draft')]}" colspan="2"/>
<button name="%(action_config_compute_remaining)d" string="Compute" type="action" colspan="1" target="new"/>
</group>
<field name="effective_hours" widget="float_time"/>
<field colspan="4" name="description" nolabel="1" select="2"/>