Tri des domaines par leur id
[OpenERP/cmmi.git] / projet.py
1 #-*- coding: utf8 -*-
2 '''
3 '''
4
5 from openerp.osv import osv, fields
6 from gtk import TRUE
7
8 class Projet(osv.Model):
9
10     _name = "projet.projet"
11
12     _columns = {
13         "name": fields.char(string="Title", size=64, required=True),
14         "description": fields.text(string="Description"),
15         "domaines": fields.many2many("projet.domaine",
16                                      "projet_projet_domaine_rel",
17                                      "projets",
18                                      string="Domaines"),
19         "structures": fields.many2many("projet.structure",
20                                        "projet_projet_structure_rel",
21                                        "projets",
22                                        string="Structures"),
23         "structures_moe": fields.many2many("projet.structure",
24                                            "projet_projet_structure_rel",
25                                            "projets",
26                                            string="Structures",
27                                            domain=[('role_mo_id.type_mo', '=', "MOE")]),
28         "structures_moa": fields.many2many("projet.structure",
29                                            "projet_projet_structure_rel",
30                                            "projets",
31                                            string="Structures",
32                                            domain=[('role_mo_id.type_mo', '=', "MOA")]),
33         "team_members": fields.many2many("projet.teammember",
34                                          "projet_projet_teammember_rel",
35                                          "projets",
36                                          string="Team Members"),
37         "modules": fields.one2many("projet.module",
38                                    "projet_id",
39                                    string="Modules"),
40         "chantiers": fields.one2many("projet.chantier",
41                                      "projet_id",
42                                      string="Chantiers"),
43         "paliers": fields.one2many("projet.palier",
44                                    "projet_id",
45                                    string="Paliers"),
46         "phases": fields.one2many("projet.phase",
47                                    "projet_id",
48                                    string="Phases"),
49         "evolutions":fields.one2many("projet.evolution",
50                                      "projet_id",
51                                      string="Evolutions"),
52         "moe_id": fields.many2one("projet.moe", string="MoE", required=True),
53         "moa_id": fields.many2one("projet.moa", string="MoA", required=True),
54         "main_domain": fields.many2one("projet.domaine",
55                                        string="Domaine principal"),
56         "main_structure": fields.many2one("projet.structure",
57                                           string="Structure principale"),
58     }
59
60
61 class Evolution(osv.Model):
62     _name = "projet.evolution"
63
64     _priorites = [("incontournable", "Incontournable"),
65                   ("necessaire", "Nécéssaire"),
66                   ("utile", "Utile")]
67
68     _statuts = [("cree", "Crée"), ("encours", "En cours"),
69                 ("termine", "Terminé"), ("abandonne", "Abandonné"),
70                 ("suspendu", "Suspendu")]
71
72     _columns = {
73         "pid": fields.integer(string="PID"),
74         "name": fields.char(string="Title", size=64, required=True),
75         "description": fields.text(string="Description"),
76         "objectif": fields.text(string="Objectif"),
77         "commentaire": fields.text(string="Commentaire"),
78         "keywords": fields.text(string="Mots clés"),
79         "priorite": fields.selection(_priorites, string="Priorité"),
80         "statut": fields.selection(_statuts, string="Statut"),
81         "charges": fields.one2many("projet.charge",
82                                    "evolution_id",
83                                    string="Charges"),
84         "module_id": fields.many2one("projet.module",
85                                      string="Modules"),
86         "chantier_id": fields.many2one("projet.chantier",
87                                     string="Chantier"),
88         "palier_id": fields.many2one("projet.palier",
89                                      string="Palier"),
90         "phase_id": fields.many2one("projet.phase",
91                                     string="Phase"),
92         "projet_id": fields.many2one("projet.projet",
93                                      string="Projet"),
94     }
95
96
97 class Structure(osv.Model):
98
99     _name = "projet.structure"
100
101     _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
102
103     _columns = {
104         "name": fields.char(string="Title", size=64, required=True),
105         "code": fields.char(string="Code", size=8, required=True),
106         "description": fields.text(string="Description"),
107         "parent_id": fields.many2one("projet.structure", string="Parent_id"),
108         "statut": fields.selection(_statuts, string="Statut"),
109         "role_mo_id":fields.many2one("projet.role_mo", string="Role MO"),
110         "projets": fields.many2many("projet.projet",
111                                     "projet_projet_structure_rel",
112                                     "structures",
113                                     string="Projets"),
114     }
115
116
117 class Role_MO(osv.Model):
118     _name = "projet.role_mo"
119
120     _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
121
122     _types_mo = [("MOE", "MOE"), ("MOA", "MOA")]
123
124     _columns = {
125         "name": fields.char(string="Title", size=64, required=True),
126         "code": fields.char(string="Code", size=8, required=True),
127         "description": fields.text(string="Description"),
128         "statut": fields.selection(_statuts, string="Statut"),
129         "type_mo": fields.selection(_types_mo, string="Type de MO", required=True),
130         "structures": fields.one2many("projet.structure",
131                                    "role_mo_id",
132                                    string="MOs"),
133         "mo_ids": fields.one2many("projet.mo",
134                                    "role_mo_id",
135                                    string="MOs"),
136     }
137
138 class Module(osv.Model):
139     _name = "projet.module"
140
141     _columns = {
142         "name": fields.char(string="Title", size=64, required=True),
143         "description": fields.text(string="Description"),
144         "projet_id": fields.many2one("projet.projet",
145                                      string="Projet",
146                                      required=True),
147         "evolutions": fields.one2many("projet.evolution",
148                                       "module_id",
149                                       string="Evolutions")
150     }
151
152
153 class Domaine(osv.Model):
154     _name = "projet.domaine"
155
156     _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
157
158     _columns = {
159         "name": fields.char(string="Title", size=64, required=True),
160         "code": fields.char(string="Code", size=8),
161         "description": fields.text(string="Description"),
162         "ordre": fields.integer(string="Ordre"),
163         "parent_id": fields.many2one("projet.domaine", string="Parent_id"),
164         "statut": fields.selection(_statuts, string="Statut"),
165         "projets": fields.many2many("projet.projet",
166                                     "projet_projet_structure_rel",
167                                     "domaines",
168                                     string="Projets"),
169     }
170
171     _order = "id"
172
173
174 class Teammember(osv.Model):
175     _name = "projet.teammember"
176
177     _inherit = "res.partner"
178
179     _columns = {
180         "projets": fields.many2many("projet.projet",
181                                     "projet_projet_teammember_rel",
182                                     "team_members",
183                                     string="Projets"),
184         "charges": fields.one2many("projet.projet",
185                                    "team_members",
186                                    string="Charges"),
187     }
188
189
190 class Type_Phase(osv.Model):
191     _name = "projet.type_phase"
192
193     _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
194
195     _columns = {
196         "name": fields.char(string="Title", size=64, required=True),
197         "description": fields.text(string="Description"),
198         "statut": fields.selection(_statuts, string="Statut"),
199     }
200
201
202 class Phase(osv.Model):
203     _name = "projet.phase"
204
205     _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
206
207
208     _columns = {
209         "name": fields.char(string="Title", size=64, required=True),
210         "description": fields.text(string="Description"),
211         "statut": fields.selection(_statuts, string="Statut"),
212         "type_phase_id": fields.many2one("projet.type_phase",
213                                          string="Type phase"),
214         "projet_id": fields.many2one("projet.projet",
215                                      string="Projet",
216                                      required=True),
217         "charges": fields.one2many("projet.charge",
218                                    "phase_id",
219                                    string="Charges"),
220         "evolutions": fields.one2many("projet.evolution",
221                                       "phase_id",
222                                       string="Evolutions"),
223         "palier_id": fields.many2one("projet.palier",
224                                      string="Palier"),
225     }
226
227 #TODO trouver un nom a cette chose
228 class qqch(osv.Model):
229     _name = "projet.qqch"
230
231     _statuts = [("cree", "Crée"), ("encours", "En cours"),
232                 ("termine", "Terminé"), ("abandonne", "Abandonné"),
233                 ("suspendu", "Suspendu"), ("generique", "Générique")]
234
235     _columns = {
236         "name": fields.char(string="Title", size=64, required=True),
237         "description": fields.text(string="Description"),
238         "commentaire": fields.text(string="Commentaire"),
239         "statut": fields.selection(_statuts, string="Statut"),
240         "version": fields.char(string="Version", size=16),
241         "date_jalon": fields.date(string="Jalon"),
242         "date_init_deb": fields.date(string="Date initiale début"),
243         "date_init_fin": fields.date(string="Date initiale de fin"),
244         "date_plan_deb": fields.date(string="Date plannifiée début"),
245         "date_plan_fin": fields.date(string="Date plannifiée de fin"),
246         "date_reel_deb": fields.date(string="Data réelle début"),
247         "date_reel_fin": fields.date(string="Data réelle fin"),
248     }
249
250     _sql_constraints = [
251         (
252             "date_init_deb_before_date_init_fin",
253             "CHECK(date_init_deb<> date_init_fin)",
254             "The date_init_deb should be previous date_init_fin",
255         ),
256         (
257             "date_plan_deb_before_date_plan_fin",
258             "CHECK(date_plan_deb <> date_plan_fin)",
259             "The date_plan_deb should be previous date_plan_fin",
260         ),
261         (
262             "date_reel_deb_before_date_reel_fin",
263             "CHECK(date_reel_deb<> date_reel_fin)",
264             "The date_reel_deb should be previous date_reel_fin",
265         ),
266     ]
267
268
269 class Chantier(osv.Model):
270     _name = "projet.chantier"
271
272     _inherit = "projet.qqch"
273
274     _columns = {
275         "projet_id": fields.many2one("projet.projet",
276                                      string="Projet",
277                                      required=True),
278         "evolutions": fields.one2many("projet.evolution",
279                                       "chantier_id",
280                                       string="Evolutions"),
281     }
282
283
284 class Palier(osv.Model):
285     _name = "projet.palier"
286
287     _types_palier = [("normal", "Normal"), ("exceptionnel", "Exceptionnel"),
288                      ("correctif", "Correctif"), ("autre", "Autre")]
289
290     _inherit = "projet.qqch"
291
292     _columns = {
293         "type_palier": fields.selection(_types_palier, string="Type"),
294         "projet_id": fields.many2one("projet.projet",
295                                      string="Projet",
296                                      required=True),
297         "evolutions": fields.one2many("projet.evolution",
298                                       "palier_id",
299                                       string="Evolutions"),
300         "phases": fields.one2many("projet.phase",
301                                   "palier_id",
302                                   string="Phases"),
303     }
304
305
306 class Charge(osv.Model):
307     _name = "projet.charge"
308
309     _columns = {
310         "name": fields.char(string="Title", size=64, required=True),
311         "description": fields.text(string="Description"),
312         "teammember_id": fields.many2one("projet.teammember",
313                                          string="Team Member",
314                                          required=True),
315         "phase_id": fields.many2one("projet.phase",
316                                     string="Phase",
317                                     required=True),
318         "evolution_id": fields.many2one("projet.evolution",
319                                     string="Evolution",
320                                     required=True),
321         "mo_id": fields.many2one("projet.mo",
322                                  string="Mo"),
323     }
324
325 class mo(osv.Model):
326     _name = "projet.mo"
327
328     _choses = [("primaire", "Primaire"),
329                ("secondaire", "Secondaire"),
330                ("generique", "Générique")]
331
332     _columns = {
333         "name": fields.char(string="Title"),
334         "description": fields.text(string="Description"),
335         "chose": fields.selection(_choses, string="Chose", required=True),
336         "role_mo_id": fields.many2one("projet.role_mo", string="Role"),
337         "charges": fields.one2many("projet.charge",
338                                    "mo_id",
339                                    string="Charges"),
340     }
341
342     _defaults = {
343         "chose": "generique"}
344
345
346 class moe(osv.Model):
347     _name = "projet.moe"
348     _inherit = "projet.mo"
349
350     _columns = {
351         "projets": fields.one2many("projet.projet",
352                                      "moe_id",
353                                      string="Projets"),
354     }
355
356
357 class moa(osv.Model):
358     _name= "projet.moa"
359     _inherit = "projet.mo"
360
361     _columns = {
362         "projets": fields.one2many("projet.projet",
363                                      "moa_id",
364                                      string="Projets"),
365     }