Task : modification contrainte, manday doit etre>= 0
[OpenERP/todolist.git] / todolist.py
index 7eeb05c..e1be67c 100644 (file)
@@ -30,16 +30,30 @@ class Container(osv.Model):
         return result
 
 
+    #================================================================================
+    # def copy(self, cr, uid, id, default, context=None):
+    #    container = self.browse(cr, uid, id, context=context)
+    #    new_name =  "Copy of %s" % container.name
+    #    # =like is the original LIKE operator from SQL
+    #    others_count = self.search(cr,  uid, [('name', '=like', new_name+'%')],
+    #                               count=True, context=context)
+    #    if others_count > 0:
+    #        new_name = "%s (%s)" % (new_name, others_count+1)
+    #    default['name'] = new_name
+    #    return osv.Model.copy(self, cr, uid, id, default, context=context)
+    #================================================================================
+
+
     def copy(self, cr, uid, id, default, context=None):
-        container = self.browse(cr, uid, id, context=context)
-        new_name =  "Copy of %s" % container.name
-        # =like is the original LIKE operator from SQL
-        others_count = self.search(cr,  uid, [('name', '=like', new_name+'%')],
-                                   count=True, context=context)
-        if others_count > 0:
-            new_name = "%s (%s)" % (new_name, others_count+1)
-        default['name'] = new_name
-        return osv.Model.copy(self, cr, uid, id, default, context=context)
+        cr.execute("SELECT copierContainer (%s);", (id,))
+        return cr.fetchone()[0]
+
+
+    def _get_manday(self, cr, uid, ids, field, arg, context=None):
+        result={}
+        for container in self.browse(cr, uid, ids, context=context):
+            result[container.id] = sum([t.manday for t in container.tasks if t.state != "done"])
+        return result
 
 
     _name = "todolist.container"
@@ -51,7 +65,7 @@ class Container(osv.Model):
         "description": fields.text(string="Description"),
         "target": fields.date(string="Target", help="Target Date"),
         "milestone": fields.date(string="Milestone", help="Due date"),
-        "manday": fields.float(string="Man-Days", digits=(6, 2)),
+        "manday": fields.function(_get_manday, type="integer", string="Man-Days"),
         "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")]),
@@ -141,7 +155,7 @@ class Task(osv.Model):
         ),
         (
             "manday_sup_0_constraint",
-            "CHECK(manday > 0)",
+            "CHECK(manday >= 0)",
             "The manday should be positive",
         ),
     ]
@@ -182,7 +196,6 @@ class Task(osv.Model):
         return osv.Model.write(self, cr, user, ids, vals, context)
 
     def create(self, cr, user, vals, context=None):
-        import pdb; pdb.set_trace()
         container_model = self.pool.get("todolist.container")
         container = container_model.read(cr, user, vals["container_id"], context=context)
         milestone = container["milestone"]