Modification contraintes : planned <= milestone et target <= milestone
[OpenERP/todolist.git] / todolist.py
index 8b0713e..57adec9 100644 (file)
@@ -30,26 +30,36 @@ 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])
+            result[container.id] = sum([t.manday for t in container.tasks if t.state != "done"])
         return result
 
 
     _name = "todolist.container"
 
+    _inherit = "mail.thread"
+
     _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")]
 
     _columns = {
@@ -78,7 +88,7 @@ class Container(osv.Model):
         ),
         (
             "target_before_milestone_constraint",
-            "CHECK(target < milestone)",
+            "CHECK(target <= milestone)",
             "The target date should be previous milestone date",
         ),
     ]
@@ -112,6 +122,8 @@ class Task(osv.Model):
 
     _name = "todolist.task"
 
+    _inherit = "mail.thread"
+
     _priorities = [("Useful", "Useful"), ("Necessary", "Necessary"), ("Essential", "Essential")]
 
     _states = [("draft", "Draft"), ("proposal", "Proposal"), ("approved", "Approved"), ("started", "Started"), ("done", "Done")]
@@ -142,12 +154,12 @@ class Task(osv.Model):
         ),
         (
             "planned_before_milestone_constraint",
-            "CHECK(planned < milestone)",
+            "CHECK(planned <= milestone)",
             "The planned date should be previous milestone date",
         ),
         (
             "manday_sup_0_constraint",
-            "CHECK(manday > 0)",
+            "CHECK(manday >= 0)",
             "The manday should be positive",
         ),
     ]
@@ -229,6 +241,8 @@ class Topic(osv.Model):
 
     _name = "todolist.topic"
 
+    _inherit = "mail.thread"
+
     _states = [("Active", "Active"), ("Inactive", "Inactive")]
 
     _columns = {