Refactoring # 1
[OpenERP/todolist.git] / todolist.py
1 #-*- coding: utf8 -*-
2
3 from openerp.osv import osv, fields
4
5
6
7
8 class Container(osv.Model):
9     """TODO List : Tasks container"""
10
11     _name = "todolist.container"
12
13     _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")]
14
15     _columns = {
16         "name": fields.char(string="Title", size=64, required=True),
17         "description": fields.text(string="Description"),
18         "target": fields.date(string="Target", help="Target Date"),
19         "milestone": fields.date(string="Milestone", help="Due date"),
20         "manday": fields.float(string="Man-Days", digits=(6, 2)),
21         "state": fields.selection(_status, string="State", select=True),
22         "tasks": fields.one2many("todolist.task", "container_id", string="Tasks"),
23         "topics_id": fields.many2many("todolist.topic", "todolist_container_topic_rel", "container_id", "topic_id", string="Topics", domain=[("activated", "=","Active")]),
24     }
25
26     _defaults = {
27         "state": "draft",
28     }
29
30     _sql_constraints = [
31         (
32             "name_different_from_description_constraint",
33             "CHECK(name <> description)",
34             "Fields name and description should be different",
35         ),
36         (
37             "target_before_milestone_constraint",
38             "CHECK(target < milestone)",
39             "The target date should be previous milestone date",
40         ),
41     ]
42
43     def action_start(self, cr, uid, ids, context=None):
44         self.write(cr, uid, ids, {"state": "pending"}, context=context)
45         return self
46
47
48     def action_stop(self, cr, uid, ids, context=None):
49         self.write(cr, uid, ids, {"state": "done"}, context=context)
50         return self
51
52
53     def action_restart(self, cr, uid, ids, context=None):
54         self.write(cr, uid, ids, {"state": "draft"}, context=context)
55         return self
56
57
58
59
60 class Task(osv.Model):
61     """TODO List : A task (something to do in a to do list)"""
62
63     _name = "todolist.task"
64
65     _priorities = [("useful", "Useful"), ("necessary", "Necessary"), ("essential", "Essential")]
66
67     _states = [("draft", "Draft"), ("proposal", "Proposal"), ("approved", "Approved"), ("started", "Started"), ("done", "Done")]
68
69     _columns = {
70         "name": fields.char(string="Title", size=64, required=True),
71         "description": fields.text(string="Description"),
72         "planned": fields.date(string="Planed"),
73         "milestone": fields.date(string="Milestone"),
74         "manday": fields.integer(string="Man-Days"),
75         "priority": fields.selection(_priorities, string="Priority", select=True),
76         "state": fields.selection(_states, string="State", select=True),
77         "container_id": fields.many2one("todolist.container", string="To do list", required=True),
78     }
79
80     _defaults = {
81         "state": "draft"
82     }
83
84     def action_draft(self, cr, uid, ids, context=None):
85         self.write(cr, uid, ids, {"state": "draft"}, context=context)
86         return self
87
88     def action_propose(self, cr, uid, ids, context=None):
89         self.write(cr, uid, ids, {"state": "proposal"}, context=context)
90         return self
91
92     def action_approve(self, cr, uid, ids, context=None):
93         self.write(cr, uid, ids, {"state": "approved"}, context=context)
94         return self
95
96     def action_start(self, cr, uid, ids, context=None):
97         self.write(cr, uid, ids, {"state": "started"}, context=context)
98         return self
99
100     def action_done(self, cr, uid, ids, context=None):
101         self.write(cr, uid, ids, {"state": "done"}, context=context)
102         return self
103
104
105 # ------------------- class Theme ------------------- #
106
107 class Topic(osv.Model):
108     """TODO List : Container"s Topic"""
109
110     _name = "todolist.topic"
111
112     _states = [("Active", "Active"), ("Inactive", "Inactive")]
113
114     _columns = {
115         "name": fields.char(string="Title", size=64, required=True),
116         "description": fields.text(string="Description"),
117         "activated": fields.selection(_states, string="State", select=True),
118         "todolist_ids": fields.many2many("todolist.container", "todolist_container_topic_rel", "topic_id", "Container_id", string="TO DO Lists"),
119     }
120
121     _defaults = {
122         "activated": "Active",
123     }