Ajout barre de progression taches faites/taches
authorAlicia FLOREZ <alicflorez@gmail.com>
Tue, 19 Mar 2013 17:01:52 +0000 (18:01 +0100)
committerAlicia FLOREZ <alicflorez@gmail.com>
Tue, 19 Mar 2013 17:01:52 +0000 (18:01 +0100)
todolist.py
views/todolist.xml

index c25f457..14d9f16 100644 (file)
@@ -11,8 +11,31 @@ class Container(osv.Model):
 
     def _get_nb_task(self, cr, uid, ids, field, arg, context=None):
         result = {}
-        for tasks in self.browse(cr, uid, ids, context=context):
-            result[tasks.id] = len(tasks.tasks)
+        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] = done/total
+        return result
+
+
+    def _task_progress2(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] = done/total*100.
         return result
 
 
@@ -30,6 +53,7 @@ class Container(osv.Model):
         "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"),
     }
 
     _defaults = {
index 600c122..d4ce132 100644 (file)
@@ -22,6 +22,7 @@
                             <field name="description" colspan="2" nolabel="1" />
                             <label for="number_tasks" colspan="1" />
                             <field name="number_tasks" colspan="2" nolabel="1" />
+                            <field name="progress_tasks" colspan="3" widget="progressbar" />
                         </group>
                         <notebook colspan="4">
                             <page string="Dates">