Ajout nombre de tache par liste
[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
12     def _get_nb_task(self, cr, uid, ids, field, arg, context=None):
13         result = {}
14         for tasks in self.browse(cr, uid, ids, context=context):
15             result[tasks.id] = len(tasks.tasks)
16         return result
17
18
19     _name = "todolist.container"
20
21     _status = [("draft", "Draft"), ("pending", "Pending"), ("done", "Done")]
22
23     _columns = {
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"),
33     }
34
35     _defaults = {
36         "state": "draft",
37     }
38
39     _sql_constraints = [
40         (
41             "name_different_from_description_constraint",
42             "CHECK(name <> description)",
43             "Fields name and description should be different",
44         ),
45         (
46             "target_before_milestone_constraint",
47             "CHECK(target < milestone)",
48             "The target date should be previous milestone date",
49         ),
50     ]
51
52     def action_start(self, cr, uid, ids, context=None):
53         self.write(cr, uid, ids, {"state": "pending"}, context=context)
54         return self
55
56
57     def action_stop(self, cr, uid, ids, context=None):
58         self.write(cr, uid, ids, {"state": "done"}, context=context)
59         return self
60
61
62     def action_restart(self, cr, uid, ids, context=None):
63         self.write(cr, uid, ids, {"state": "draft"}, context=context)
64         return self
65
66
67
68
69 class Task(osv.Model):
70     """TODO List : A task (something to do in a to do list)"""
71
72     _name = "todolist.task"
73
74     _priorities = [("useful", "Useful"), ("necessary", "Necessary"), ("essential", "Essential")]
75
76     _states = [("draft", "Draft"), ("proposal", "Proposal"), ("approved", "Approved"), ("started", "Started"), ("done", "Done")]
77
78     _columns = {
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),
87     }
88
89     _defaults = {
90         "state": "draft"
91     }
92
93     def action_draft(self, cr, uid, ids, context=None):
94         self.write(cr, uid, ids, {"state": "draft"}, context=context)
95         return self
96
97     def action_propose(self, cr, uid, ids, context=None):
98         self.write(cr, uid, ids, {"state": "proposal"}, context=context)
99         return self
100
101     def action_approve(self, cr, uid, ids, context=None):
102         self.write(cr, uid, ids, {"state": "approved"}, context=context)
103         return self
104
105     def action_start(self, cr, uid, ids, context=None):
106         self.write(cr, uid, ids, {"state": "started"}, context=context)
107         return self
108
109     def action_done(self, cr, uid, ids, context=None):
110         self.write(cr, uid, ids, {"state": "done"}, context=context)
111         return self
112
113
114 # ------------------- class Theme ------------------- #
115
116 class Topic(osv.Model):
117     """TODO List : Container"s Topic"""
118
119     _name = "todolist.topic"
120
121     _states = [("Active", "Active"), ("Inactive", "Inactive")]
122
123     _columns = {
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"),
128     }
129
130     _defaults = {
131         "activated": "Active",
132     }