Un user ne peut voir que ses propres container
[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     def search(self, cr, user, args=[], offset=0, limit=None, order=None, context=None, count=False):
59         args.append(("create_uid", "=", user))
60         if len(args) != 1:
61             args.insert(0, "&")
62         return osv.Model.search(self, cr, user, args, offset, limit, order, context, count)
63
64
65 class Task(osv.Model):
66     """TODO List : A task (something to do in a to do list)"""
67
68     _name = "todolist.task"
69
70     _priorities = [("useful", "Useful"), ("necessary", "Necessary"), ("essential", "Essential")]
71
72     _states = [("draft", "Draft"), ("proposal", "Proposal"), ("approved", "Approved"), ("started", "Started"), ("done", "Done")]
73
74     _columns = {
75         "name": fields.char(string="Title", size=64, required=True),
76         "description": fields.text(string="Description"),
77         "planned": fields.date(string="Planed"),
78         "milestone": fields.date(string="Milestone"),
79         "manday": fields.integer(string="Man-Days"),
80         "priority": fields.selection(_priorities, string="Priority", select=True),
81         "state": fields.selection(_states, string="State", select=True),
82         "container_id": fields.many2one("todolist.container", string="To do list", required=True),
83     }
84
85     _defaults = {
86         "state": "draft"
87     }
88
89     def action_draft(self, cr, uid, ids, context=None):
90         self.write(cr, uid, ids, {"state": "draft"}, context=context)
91         return self
92
93     def action_propose(self, cr, uid, ids, context=None):
94         self.write(cr, uid, ids, {"state": "proposal"}, context=context)
95         return self
96
97     def action_approve(self, cr, uid, ids, context=None):
98         self.write(cr, uid, ids, {"state": "approved"}, context=context)
99         return self
100
101     def action_start(self, cr, uid, ids, context=None):
102         self.write(cr, uid, ids, {"state": "started"}, context=context)
103         return self
104
105     def action_done(self, cr, uid, ids, context=None):
106         self.write(cr, uid, ids, {"state": "done"}, context=context)
107         return self
108
109
110 # ------------------- class Theme ------------------- #
111
112 class Topic(osv.Model):
113     """TODO List : Container"s Topic"""
114
115     _name = "todolist.topic"
116
117     _states = [("Active", "Active"), ("Inactive", "Inactive")]
118
119     _columns = {
120         "name": fields.char(string="Title", size=64, required=True),
121         "description": fields.text(string="Description"),
122         "activated": fields.selection(_states, string="State", select=True),
123         "todolist_ids": fields.many2many("todolist.container", "todolist_container_topic_rel", "topic_id", "Container_id", string="TO DO Lists"),
124     }
125
126     _defaults = {
127         "activated": "Active",
128     }