Champs fonction pour nb de taches par listes
authorAlicia FLOREZ <alicflorez@gmail.com>
Wed, 20 Mar 2013 16:26:41 +0000 (17:26 +0100)
committerAlicia FLOREZ <alicflorez@gmail.com>
Wed, 20 Mar 2013 16:26:41 +0000 (17:26 +0100)
todolist.py
views/todolist.xml

index a919d15..2935ab6 100644 (file)
@@ -9,36 +9,25 @@ class Container(osv.Model):
     """TODO List : Tasks container"""
 
 
-    def _get_nb_task(self, cr, uid, ids, field, arg, context=None):
+    def _get_nb_tasks(self, cr, uid, ids, field, arg, context=None):
         result = {}
         for container in self.browse(cr, uid, ids, context=context):
             result[container.id] = len(container.tasks)
         return result
 #        return dict((c.id, len(c.tasks)) for c in self.browse(cr, uid, ids, context=context))
 
-
-    def _task_progress(self, cr, uid, ids, field, arg, context=None):
-        result = {}
-        for container in self.browse(cr, uid, ids, context=context):
-            done = total = 0
-            for task in container.tasks.browse(cr, uid, ids, context=context):
-                total += 1
-                if task.state == "done":
-                    done += 1
-            result[container.id] = total and done/total or 0.
+    def _get_nb_tasks_done(self, cr, uid, ids, field, arg, context=None):
+        result={}
+        for c in self.browse(cr, uid, ids, context=context):
+            result[c.id] = len([t for t in c.tasks if t.state == "done"])
         return result
 
-
-    def _task_progress2(self, cr, uid, ids, field, arg, context=None):
+    def _tasks_progress(self, cr, uid, ids, field, arg, context=None):
         result = {}
-        for container in self.browse(cr, uid, ids, context=context):
-            tasks = container.tasks
-            total = len(tasks)
-            done = len([t for t in tasks if t.state == "done"])
-            result[container.id] = total and done/total or 0.
+        for c in self.browse(cr, uid, ids, context=context):
+            result[c.id] = c.number_tasks and c.number_tasks_done*100./c.number_tasks or 0.
         return result
 
-
     _name = "todolist.container"
 
     _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")]
@@ -52,8 +41,9 @@ class Container(osv.Model):
         "state": fields.selection(_status, string="State", select=True),
         "tasks": fields.one2many("todolist.task", "container_id", string="Tasks"),
         "topics_id": fields.many2many("todolist.topic", "todolist_container_topic_rel", "container_id", "topic_id", string="Topics", domain=[("activated", "=","Active")]),
-        "number_tasks": fields.function(_get_nb_task, type="integer", string="Number of tasks"),
-        "progress_tasks": fields.function(_task_progress2, type="float", string="Progression"),
+        "number_tasks": fields.function(_get_nb_tasks, type="integer", string="Number of tasks"),
+        "number_tasks_done": fields.function(_get_nb_tasks_done, type="integer", string="Number of tasks"),
+        "progress_tasks": fields.function(_tasks_progress, type="float", string="Progression"),
     }
 
     _defaults = {
index 6e84165..815e892 100644 (file)
@@ -22,6 +22,8 @@
                             <field name="description" colspan="2" nolabel="1" />
                             <label for="number_tasks" colspan="1" />
                             <field name="number_tasks" colspan="2" nolabel="1" />
+                            <label for="number_tasks_done" colspan="1" />
+                            <field name="number_tasks_done" colspan="2" nolabel="1" />
                             <field name="progress_tasks" colspan="3" widget="progressbar" />
                         </group>
                         <notebook colspan="4">