Ajout d'un domaine et d'une structure principale pour un projet
[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
172 class Teammember(osv.Model):
173     _name = "projet.teammember"
174
175     _inherit = "res.partner"
176
177     _columns = {
178         "projets": fields.many2many("projet.projet",
179                                     "projet_projet_teammember_rel",
180                                     "team_members",
181                                     string="Projets"),
182         "charges": fields.one2many("projet.projet",
183                                    "team_members",
184                                    string="Charges"),
185     }
186
187
188 class Type_Phase(osv.Model):
189     _name = "projet.type_phase"
190
191     _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
192
193     _columns = {
194         "name": fields.char(string="Title", size=64, required=True),
195         "description": fields.text(string="Description"),
196         "statut": fields.selection(_statuts, string="Statut"),
197     }
198
199
200 class Phase(osv.Model):
201     _name = "projet.phase"
202
203     _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
204
205
206     _columns = {
207         "name": fields.char(string="Title", size=64, required=True),
208         "description": fields.text(string="Description"),
209         "statut": fields.selection(_statuts, string="Statut"),
210         "type_phase_id": fields.many2one("projet.type_phase",
211                                          string="Type phase"),
212         "projet_id": fields.many2one("projet.projet",
213                                      string="Projet",
214                                      required=True),
215         "charges": fields.one2many("projet.charge",
216                                    "phase_id",
217                                    string="Charges"),
218         "evolutions": fields.one2many("projet.evolution",
219                                       "phase_id",
220                                       string="Evolutions"),
221         "palier_id": fields.many2one("projet.palier",
222                                      string="Palier"),
223     }
224
225 #TODO trouver un nom a cette chose
226 class qqch(osv.Model):
227     _name = "projet.qqch"
228
229     _statuts = [("cree", "Crée"), ("encours", "En cours"),
230                 ("termine", "Terminé"), ("abandonne", "Abandonné"),
231                 ("suspendu", "Suspendu"), ("generique", "Générique")]
232
233     _columns = {
234         "name": fields.char(string="Title", size=64, required=True),
235         "description": fields.text(string="Description"),
236         "commentaire": fields.text(string="Commentaire"),
237         "statut": fields.selection(_statuts, string="Statut"),
238         "version": fields.char(string="Version", size=16),
239         "date_jalon": fields.date(sring="Jalon"),
240         "date_init_deb": fields.date(sring="Date initiale début"),
241         "date_init_fin": fields.date(sring="Date initiale de fin"),
242         "date_plan_deb": fields.date(string="Date plannifiée début"),
243         "date_plan_fin": fields.date(string="Date plannifiée de fin"),
244         "date_reel_deb": fields.date(string="Data réelle début"),
245         "date_reel_fin": fields.date(string="Data réelle fin"),
246     }
247
248     _sql_constraints = [
249         (
250             "date_init_deb_before_date_init_fin",
251             "CHECK(date_init_deb<> date_init_fin)",
252             "The date_init_deb should be previous date_init_fin",
253         ),
254         (
255             "date_plan_deb_before_date_plan_fin",
256             "CHECK(date_plan_deb <> date_plan_fin)",
257             "The date_plan_deb should be previous date_plan_fin",
258         ),
259         (
260             "date_reel_deb_before_date_reel_fin",
261             "CHECK(date_reel_deb<> date_reel_fin)",
262             "The date_reel_deb should be previous date_reel_fin",
263         ),
264     ]
265
266
267 class Chantier(osv.Model):
268     _name = "projet.chantier"
269
270     _inherit = "projet.qqch"
271
272     _columns = {
273         "projet_id": fields.many2one("projet.projet",
274                                      string="Projet",
275                                      required=True),
276         "evolutions": fields.one2many("projet.evolution",
277                                       "chantier_id",
278                                       string="Evolutions"),
279     }
280
281
282 class Palier(osv.Model):
283     _name = "projet.palier"
284
285     _types_palier = [("normal", "Normal"), ("exceptionnel", "Exceptionnel"),
286                      ("correctif", "Correctif"), ("autre", "Autre")]
287
288     _inherit = "projet.qqch"
289
290     _columns = {
291         "type_palier": fields.selection(_types_palier, string="Type"),
292         "projet_id": fields.many2one("projet.projet",
293                                      string="Projet",
294                                      required=True),
295         "evolutions": fields.one2many("projet.evolution",
296                                       "palier_id",
297                                       string="Evolutions"),
298         "phases": fields.one2many("projet.phase",
299                                   "palier_id",
300                                   string="Phases"),
301     }
302
303
304 class Charge(osv.Model):
305     _name = "projet.charge"
306
307     _columns = {
308         "name": fields.char(string="Title", size=64, required=True),
309         "description": fields.text(string="Description"),
310         "teammember_id": fields.many2one("projet.teammember",
311                                          string="Team Member",
312                                          required=True),
313         "phase_id": fields.many2one("projet.phase",
314                                     string="Phase",
315                                     required=True),
316         "evolution_id": fields.many2one("projet.evolution",
317                                     string="Evolution",
318                                     required=True),
319         "mo_id": fields.many2one("projet.mo",
320                                  string="Mo"),
321     }
322
323 class mo(osv.Model):
324     _name = "projet.mo"
325
326     _choses = [("primaire", "Primaire"),
327                ("secondaire", "Secondaire"),
328                ("generique", "Générique")]
329
330     _columns = {
331         "name": fields.char(string="Title"),
332         "description": fields.text(string="Description"),
333         "chose": fields.selection(_choses, string="Chose", required=True),
334         "role_mo_id": fields.many2one("projet.role_mo", string="Role"),
335         "charges": fields.one2many("projet.charge",
336                                    "mo_id",
337                                    string="Charges"),
338     }
339
340     _defaults = {
341         "chose": "generique"}
342
343
344 class moe(osv.Model):
345     _name = "projet.moe"
346     _inherit = "projet.mo"
347
348     _columns = {
349         "projets": fields.one2many("projet.projet",
350                                      "moe_id",
351                                      string="Projets"),
352     }
353
354
355 class moa(osv.Model):
356     _name= "projet.moa"
357     _inherit = "projet.mo"
358
359     _columns = {
360         "projets": fields.one2many("projet.projet",
361                                      "moa_id",
362                                      string="Projets"),
363     }