3 from openerp.osv import osv, fields
8 class Container(osv.Model):
9 """TODO List : Tasks container"""
12 def _get_nb_task(self, cr, uid, ids, field, arg, context=None):
14 for tasks in self.browse(cr, uid, ids, context=context):
15 result[tasks.id] = len(tasks.tasks)
19 _name = "todolist.container"
21 _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")]
24 "name": fields.char(string="Title", size=64, required=True),
25 "description": fields.text(string="Description"),
26 "target": fields.date(string="Target", help="Target Date"),
27 "milestone": fields.date(string="Milestone", help="Due date"),
28 "manday": fields.float(string="Man-Days", digits=(6, 2)),
29 "state": fields.selection(_status, string="State", select=True),
30 "tasks": fields.one2many("todolist.task", "container_id", string="Tasks"),
31 "topics_id": fields.many2many("todolist.topic", "todolist_container_topic_rel", "container_id", "topic_id", string="Topics", domain=[("activated", "=","Active")]),
32 "number_tasks": fields.function(_get_nb_task, type="integer", string="Number of tasks"),
41 "name_different_from_description_constraint",
42 "CHECK(name <> description)",
43 "Fields name and description should be different",
46 "target_before_milestone_constraint",
47 "CHECK(target < milestone)",
48 "The target date should be previous milestone date",
52 def action_start(self, cr, uid, ids, context=None):
53 self.write(cr, uid, ids, {"state": "pending"}, context=context)
57 def action_stop(self, cr, uid, ids, context=None):
58 self.write(cr, uid, ids, {"state": "done"}, context=context)
62 def action_restart(self, cr, uid, ids, context=None):
63 self.write(cr, uid, ids, {"state": "draft"}, context=context)
69 class Task(osv.Model):
70 """TODO List : A task (something to do in a to do list)"""
72 _name = "todolist.task"
74 _priorities = [("useful", "Useful"), ("necessary", "Necessary"), ("essential", "Essential")]
76 _states = [("draft", "Draft"), ("proposal", "Proposal"), ("approved", "Approved"), ("started", "Started"), ("done", "Done")]
79 "name": fields.char(string="Title", size=64, required=True),
80 "description": fields.text(string="Description"),
81 "planned": fields.date(string="Planed"),
82 "milestone": fields.date(string="Milestone"),
83 "manday": fields.integer(string="Man-Days"),
84 "priority": fields.selection(_priorities, string="Priority", select=True),
85 "state": fields.selection(_states, string="State", select=True),
86 "container_id": fields.many2one("todolist.container", string="To do list", required=True),
93 def action_draft(self, cr, uid, ids, context=None):
94 self.write(cr, uid, ids, {"state": "draft"}, context=context)
97 def action_propose(self, cr, uid, ids, context=None):
98 self.write(cr, uid, ids, {"state": "proposal"}, context=context)
101 def action_approve(self, cr, uid, ids, context=None):
102 self.write(cr, uid, ids, {"state": "approved"}, context=context)
105 def action_start(self, cr, uid, ids, context=None):
106 self.write(cr, uid, ids, {"state": "started"}, context=context)
109 def action_done(self, cr, uid, ids, context=None):
110 self.write(cr, uid, ids, {"state": "done"}, context=context)
114 # ------------------- class Theme ------------------- #
116 class Topic(osv.Model):
117 """TODO List : Container"s Topic"""
119 _name = "todolist.topic"
121 _states = [("Active", "Active"), ("Inactive", "Inactive")]
124 "name": fields.char(string="Title", size=64, required=True),
125 "description": fields.text(string="Description"),
126 "activated": fields.selection(_states, string="State", select=True),
127 "todolist_ids": fields.many2many("todolist.container", "todolist_container_topic_rel", "topic_id", "Container_id", string="TO DO Lists"),
131 "activated": "Active",