Kuldeep Joshi(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-823838-kjo into 
lp:openobject-addons.

Requested reviews:
  Bhumika (OpenERP) (sbh-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-823838-kjo/+merge/83780

Set the parent and child relationship so, parent project include the childe 
project hours
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-823838-kjo/+merge/83780
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-823838-kjo.
=== modified file 'project/project.py'
--- project/project.py	2011-11-23 13:31:32 +0000
+++ project/project.py	2011-11-29 13:17:31 +0000
@@ -83,11 +83,30 @@
             pricelist_id = pricelist.get('property_product_pricelist', False) and pricelist.get('property_product_pricelist')[0] or False
             val['pricelist_id'] = pricelist_id
         return {'value': val}
+    
+    def _get_childs(self,cr, uid, ids, childs, context=None):
+        cr.execute("""SELECT id FROM project_project WHERE analytic_account_id IN (
+                        SELECT id FROM account_analytic_account WHERE parent_id = (
+                            SELECT  analytic_account_id FROM project_project WHERE id = %s
+                            )
+                        )"""%(ids))
+        for child in cr.fetchall():
+            if child[0] not in childs: childs.append(child[0])
+            self._get_childs( cr, uid, child[0], childs, context)
+        return childs
+    
+    def _get_parents(self, cr, uid, ids, parents, context=None):
+        for project in self.read(cr, uid, ids, ['id', 'parent_id'],context):
+            if project.get('parent_id'):
+                cr.execute('''SELECT id FROM project_project WHERE analytic_account_id = '%s' '''%project.get('parent_id')[0])
+                for child in cr.fetchall():
+                    if child[0] not in parents: parents.append(child[0])
+                    child_rec= self.read(cr, uid, child[0], ['id', 'parent_id'],context)
+                    if child_rec.get('parent_id'):
+                        parents = self._get_parents(cr, uid, [child[0]], parents, context)
+        return parents
 
-    def _progress_rate(self, cr, uid, ids, names, arg, context=None):
-        res = {}.fromkeys(ids, 0.0)
-        if not ids:
-            return res
+    def _get_project_hours(self,cr, ids):
         cr.execute('''SELECT
                 project_id, sum(planned_hours), sum(total_hours), sum(effective_hours), SUM(remaining_hours)
             FROM
@@ -97,15 +116,45 @@
                 state<>'cancelled'
             GROUP BY
                 project_id''', (tuple(ids),))
+        return cr
+
+    def _progress_rate(self, cr, uid, ids, names, arg, context=None):
+        res = {}.fromkeys(ids, 0.0)
+        if not ids:
+            return res
+        parents = self._get_parents(cr, uid, ids, ids,context)
+        cr = self._get_project_hours(cr,ids)
+        
         progress = dict(map(lambda x: (x[0], (x[1],x[2],x[3],x[4])), cr.fetchall()))
-        for project in self.browse(cr, uid, ids, context=context):
-            s = progress.get(project.id, (0.0,0.0,0.0,0.0))
+        for project in self.browse(cr, uid, parents, context=context):
+            childs = []
+            childs = self._get_childs(cr, uid, project.id, childs, context)
+            s = progress.get(project.id, (0.0,0.0,0.0,0.0))    
             res[project.id] = {
                 'planned_hours': s[0],
                 'effective_hours': s[2],
                 'total_hours': s[1],
                 'progress_rate': s[1] and round(100.0*s[2]/s[1],2) or 0.0
             }
+
+            if childs:
+                cr =  self._get_project_hours(cr,childs)
+                child_progress = dict(map(lambda x: (x[0], (x[1] or 0.0 ,x[2] or 0.0 ,x[3] or 0.0 ,x[4] or 0.0)), cr.fetchall()))
+                planned_hours, effective_hours, total_hours, rnd= 0.0, 0.0,0.0, 0.0
+                
+                for child in childs:
+                    ch_vals = child_progress.get(child, (0.0,0.0,0.0,0.0))
+                    planned_hours, effective_hours, total_hours = planned_hours+ch_vals[0], effective_hours+ch_vals[2] , total_hours+ch_vals[1]
+
+                if res.get(project.id).get('planned_hours')+ planned_hours > 0:
+                    rnd = round(( res.get(project.id).get('effective_hours')+effective_hours)/(res.get(project.id).get('planned_hours')+ planned_hours)*100,2) or 0.0
+                   
+                res[project.id] = {
+                    'planned_hours': res.get(project.id).get('planned_hours')+ planned_hours,
+                    'effective_hours': res.get(project.id).get('effective_hours')+ effective_hours,
+                    'total_hours': res.get(project.id).get('total_hours')+ total_hours,
+                    'progress_rate':  rnd
+                }
         return res
 
     def _get_project_task(self, cr, uid, ids, context=None):

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to