bugfix for task work and remaining hours
authorHusen Daudi <hda@tinyerp.com>
Wed, 3 Dec 2008 13:38:20 +0000 (19:08 +0530)
committerHusen Daudi <hda@tinyerp.com>
Wed, 3 Dec 2008 13:38:20 +0000 (19:08 +0530)
lp bug: https://launchpad.net/bugs/304410 fixed

bzr revid: hda@tinyerp.com-20081203133820-fp0ca4k3qwk61jj2

addons/.project [deleted file]
addons/project/project.py
addons/project/project_demo.xml
addons/project/project_view.xml

diff --git a/addons/.project b/addons/.project
deleted file mode 100644 (file)
index 6b6fa8f..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-       <name>openobject-addons</name>
-       <comment></comment>
-       <projects>
-       </projects>
-       <buildSpec>
-               <buildCommand>
-                       <name>org.python.pydev.PyDevBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-       </buildSpec>
-       <natures>
-               <nature>org.python.pydev.pythonNature</nature>
-       </natures>
-</projectDescription>
index b7ff804..c2337da 100644 (file)
@@ -246,6 +246,15 @@ class task(osv.osv):
     #_sql_constraints = [
     #    ('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 {}
@@ -408,23 +417,8 @@ 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()
 
-
-
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
index 9a25d72..ea6803b 100644 (file)
@@ -89,7 +89,7 @@
             <field model="res.users" name="user_id" search="[('login','=','demo')]"/>
             <field name="project_id" ref="project_project_21"/>
             <field name="name">Internal testing + Software Install</field>
-            <field name="date_deadline">2007-06-06</field>
+            <field name="date_deadline">2008-06-06</field>
         </record>
         <record id="project_task_188" model="project.task">
             <field name="sequence">17</field>
index 9b92f22..b2d3169 100644 (file)
                                 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"/>
+                            <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"/>
                             <field name="effective_hours" widget="float_time"/>
 
                             <field colspan="4" name="description" nolabel="1" select="2"/>
         <act_window domain="[('user_id', '=', active_id),('state', '&lt;&gt;', 'cancelled'),('state', '&lt;&gt;', 'done')]" id="act_res_users_2_project_task_opened" name="Assigned tasks" res_model="project.task" src_model="res.users" view_mode="tree,form" view_type="form"/>
 
         <act_window domain="[('user_id', '=', active_id),('date', '&gt;=', time.strftime('%Y-%m-01'))]" id="act_res_users_2_project_task_work_month" name="Month works" res_model="project.task.work" src_model="res.users" view_mode="tree,form" view_type="form"/>
-
+        
     </data>
 </openerp>