Modif pour fonctionnement avec semantics : les topics héritent de ceux de semantics
[OpenERP/todolist.git] / todolist.py
index 5d0c666..2752280 100644 (file)
@@ -5,6 +5,7 @@ from openerp.osv import osv, fields
 
 
 
+# ------------- CONTAINER ------------- #
 class Container(osv.Model):
     """TODO List : Tasks container"""
 
@@ -58,6 +59,8 @@ class Container(osv.Model):
 
     _name = "todolist.container"
 
+    _inherit = "mail.thread"
+
     _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")]
 
     _columns = {
@@ -68,7 +71,12 @@ class Container(osv.Model):
         "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")]),
+        "topic_ids": fields.many2many("todolist.topic",
+                                      "todolist_container_topic_rel",
+                                      "todolist_ids",
+                                      "topic_ids",
+                                      string="Topics",
+                                      domain=[("activated", "=","Active")]),
         "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 done"),
         "progress_tasks": fields.function(_tasks_progress, type="float", string="Progression"),
@@ -86,7 +94,7 @@ class Container(osv.Model):
         ),
         (
             "target_before_milestone_constraint",
-            "CHECK(target < milestone)",
+            "CHECK(target <= milestone)",
             "The target date should be previous milestone date",
         ),
     ]
@@ -115,11 +123,14 @@ class Container(osv.Model):
         return osv.Model.search(self, cr, user, args, offset, limit, order, context, count)
 
 
+# ------------- TASK ------------- #
 class Task(osv.Model):
     """TODO List : A task (something to do in a to do list)"""
 
     _name = "todolist.task"
 
+    _inherit = "mail.thread"
+
     _priorities = [("Useful", "Useful"), ("Necessary", "Necessary"), ("Essential", "Essential")]
 
     _states = [("draft", "Draft"), ("proposal", "Proposal"), ("approved", "Approved"), ("started", "Started"), ("done", "Done")]
@@ -150,12 +161,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",
         ),
     ]
@@ -203,7 +214,7 @@ class Task(osv.Model):
             vals["milestone"] = milestone
         return osv.Model.create(self, cr, user, vals, context=context)
 
-
+# ------------- TOPIC ------------- #
 class Topic(osv.Model):
     """TODO List : Container"s Topic"""
 
@@ -237,13 +248,17 @@ class Topic(osv.Model):
 
     _name = "todolist.topic"
 
+    _inherit = "semantics.topic"
+
     _states = [("Active", "Active"), ("Inactive", "Inactive")]
 
     _columns = {
-        "name": fields.char(string="Title", size=64, required=True),
-        "description": fields.text(string="Description"),
         "activated": fields.selection(_states, string="State", select=True),
-        "todolist_ids": fields.many2many("todolist.container", "todolist_container_topic_rel", "topic_id", "Container_id", string="TO DO Lists"),
+        "todolist_ids": fields.many2many("todolist.container",
+                                         "todolist_container_topic_rel",
+                                         "topic_ids",
+                                         "todolist_ids",
+                                         string="TO DO Lists"),
         "nb_lists": fields.function(_get_nb_lists, type="integer", string="Number of lists"),
         "number_tasks": fields.function(_get_number_tasks, type="integer", string="Number of tasks"),
         "number_tasks_done": fields.function(_get_number_tasks_done, type="integer", string="Number of tasks done"),
@@ -253,12 +268,3 @@ class Topic(osv.Model):
     _defaults = {
         "activated": "Active",
     }
-
-
-    _sql_constraints = [
-        (
-            "name_different_from_description_constraint",
-            "CHECK(name <> description)",
-            "Fields name and description should be different",
-        ),
-    ]