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