Ajout de descriptions pour chaque classe
[OpenERP/cmmi.git] / projet.py
1 #-*- coding: utf8 -*-
2 '''
3 '''
4
5 from openerp.osv import osv, fields
6
7
8 class Projet(osv.Model):
9
10     _name = "cmmi.projet"
11
12     _description = "Table des projets."
13
14     def _get_main_domain(self, cr, uid, ids, field_name=None, arg=None, context=None):
15         if type(ids) in (int, float):
16             ids = [ids]
17
18         projects = self.browse(cr, uid, ids, context=context)
19
20         result = {}
21
22         for project in projects:
23             for domain in project.domains:
24                 if domain.main:
25                     result[project.id] = domain.name
26                     break
27             else:
28                 result[project.id] = "Any domain is selected as main domain yet"
29
30         return result
31
32
33     def _get_main_moa(self, cr, uid, ids, field_name=None, arg=None, context=None):
34         if type(ids) in (int, float):
35             ids = [ids]
36
37         projects = self.browse(cr, uid, ids, context=context)
38
39         result = {}
40
41         for project in projects:
42             for moa in project.moa_ids:
43                 if moa.main:
44                     result[project.id] = moa.name
45                     break
46             else:
47                 result[project.id] = "Any MOA is selected as main MOA yet"
48
49         return result
50
51
52     def _get_main_moe(self, cr, uid, ids, field_name=None, arg=None, context=None):
53         if type(ids) in (int, float):
54             ids = [ids]
55
56         projects = self.browse(cr, uid, ids, context=context)
57
58         result = {}
59
60         for project in projects:
61             for moe in project.moe_ids:
62                 if moe.main:
63                     result[project.id] = moe.name
64                     break
65             else:
66                 result[project.id] = "Any MOE is selected as main MOE yet"
67
68         return result
69
70
71     _columns = {
72         "name": fields.char(string="Title", size=64, required=True),
73         "description": fields.text(string="Description"),
74         # Backrefs
75         "domains": fields.one2many("cmmi.projet.domaine",
76                                     "project_id",
77                                     string="Domaines"),
78         "moe_ids": fields.one2many("cmmi.projet.moe",
79                                    "project_id",
80                                    string="MOEs"),
81         "moa_ids": fields.one2many("cmmi.projet.moa",
82                                    "project_id",
83                                    string="MOAs"),
84         "team_members": fields.one2many("cmmi.projet.teammember",
85                                          "projet_id",
86                                          string="Team Members"),
87         "modules": fields.one2many("cmmi.description.module",
88                                    "projet_id",
89                                    string="Modules"),
90         "chantiers": fields.one2many("cmmi.axes.chantier",
91                                      "projet_id",
92                                      string="Chantiers"),
93         "paliers": fields.one2many("cmmi.axes.palier",
94                                    "projet_id",
95                                    string="Paliers"),
96         "phases": fields.one2many("cmmi.projet.phase",
97                                   "projet_id",
98                                   string="Phases"),
99         "evolutions": fields.one2many("cmmi.evolution",
100                                       "projet_id",
101                                       string="Evolutions"),
102         # TODO: faire un champs fonction qui renvoie uniquement les domaines sélectionnés
103
104         # Champs fonction rapatriant les mo ou domaine principaux
105         "moe_id": fields.function(_get_main_moe,
106                                   type="string",
107                                   string="MOE principale"),
108         "moa_id": fields.function(_get_main_moa,
109                                   type="string",
110                                   string="MOA principale"),
111         "main_domain": fields.function(_get_main_domain,
112                                        type="string",
113                                        string="Domaine principal"),
114     }
115
116
117     def create(self, cr, uid, vals, context=None):
118         project_id = osv.Model.create(self, cr, uid, vals, context=context)
119
120         # Récupération des ids de toutes les phases
121         phase_model = self.pool.get("cmmi.phase")
122         phases_ids = phase_model.search(cr, uid, [])
123
124         # Création des relations
125         projet_phase_model = self.pool.get("cmmi.projet.phase")
126         for phase_id in phases_ids:
127             projet_phase_model.create(
128                 cr,
129                 uid,
130                 {
131                     'projet_id': project_id,
132                     'phase_id': phase_id,
133                     'selectionne': False,
134                 }
135             )
136
137         return project_id
138
139
140     def action_add_domain(self, cr, uid, ids, context=None):
141         pass
142
143     def action_add_moe(self, cr, uid, ids, context=None):
144         pass
145
146     def action_add_moa(self, cr, uid, ids, context=None):
147         pass
148
149
150
151 class ProjetDomaine(osv.Model):
152
153     _name = "cmmi.projet.domaine"
154
155     _description = "Rattachement des domaines a un projet."
156
157     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
158         if isinstance(ids, (int, long)):
159             ids = [ids]
160         #return {i: r.domaine_id.name for i, r in
161         #        zip(ids, self.browse(cr, uid, ids, context=context))}
162         return dict([(i, r.domaine_id.name) for i, r in
163                 zip(ids, self.browse(cr, uid, ids, context=context))])
164
165     _columns = {
166         "name": fields.function(_get_name,
167                                 type='char',
168                                 store=True,
169                                 string="Nom du domaine"),
170         "main": fields.boolean(string="Domaine principal ?"),
171         "project_id": fields.many2one("cmmi.projet",
172                                       string="Projet"),
173         "domaine_id": fields.many2one("cmmi.description.domaine",
174                                       string="Domaine"),
175     }
176
177     def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
178         if not main:
179             return {'value': {'main': True},
180                     'warning': {
181                         'title'   : "Integrity Warning",
182                         'message' : "One of the domains should be the main domain",
183                     }
184                 }
185         ids = self.search(
186             cr,
187             uid,
188             [
189                 ('project_id', '=', project),
190                 ('domaine_id', '!=', domaine),
191             ],
192             context=context,
193         )
194         current_id = self.search(
195             cr,
196             uid,
197             [
198                 ('project_id', '=', project),
199                 ('domaine_id', '=', domaine),
200             ],
201             context=context,
202         )
203         self.write(cr, uid, ids, {'main': False}, context=context)
204         self.write(cr, uid, current_id, {'main': True}, context=context)
205
206         return {'value': {'main': True}}
207
208
209
210 class ProjetMoe(osv.Model):
211     _name = "cmmi.projet.moe"
212
213     _description = "Rattachement des MOEs au projet."
214
215     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
216         if isinstance(ids, (int, long)):
217             ids = [ids]
218         return dict([(i, r.moe_id.name) for i, r in
219                 zip(ids, self.browse(cr, uid, ids, context=context))])
220
221     _columns = {
222         "name": fields.function(_get_name,
223                                 type='char',
224                                 store=True, # Permet d'enregistrer le champ.
225                                 string="Nom de la MOE"),
226         "main": fields.boolean(string="MOE principale ?"),
227         "project_id": fields.many2one("cmmi.projet",
228                                       string="Projet",
229                                       required=True),
230         "moe_id": fields.many2one("cmmi.mo.moe",
231                                   string="MOE",
232                                   required=True),
233     }
234
235     def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
236         if not main:
237             return {'value': {'main': True},
238                     'warning': {
239                         'title'   : "Integrity Warning",
240                         'message' : "Une des MOE doit être la MOE principale",
241                     }
242                 }
243         ids = self.search(
244             cr,
245             uid,
246             [
247                 ('project_id', '=', project),
248                 ('moe_id', '!=', moe),
249             ],
250             context=context,
251         )
252         current_id = self.search(
253             cr,
254             uid,
255             [
256                 ('project_id', '=', project),
257                 ('moe_id', '=', moe),
258             ],
259             context=context,
260         )
261         self.write(cr, uid, ids, {'main': False}, context=context)
262         self.write(cr, uid, current_id, {'main': True}, context=context)
263
264         return {'value': {'main': True}}
265
266
267
268 class ProjetMoa(osv.Model):
269     _name = "cmmi.projet.moa"
270
271     _description = "Rattachement des MOAs a une projet."
272
273     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
274         if isinstance(ids, (int, long)):
275             ids = [ids]
276         return dict([(i, r.moa_id.name) for i, r in
277                 zip(ids, self.browse(cr, uid, ids, context=context))])
278
279     _columns = {
280         "name": fields.function(_get_name,
281                                 type='char',
282                                 store=True,
283                                 string="Nom de la MOA"),
284         "main": fields.boolean(string="MOA principale ?"),
285         "project_id": fields.many2one("cmmi.projet",
286                                       string="Projet",
287                                       required=True),
288         "moa_id": fields.many2one("cmmi.mo.moa",
289                                   string="MOA",
290                                   required=True),
291     }
292
293     def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
294         if not main:
295             return {'value': {'main': True},
296                     'warning': {
297                         'title'   : "Integrity Warning",
298                         'message' : "Une des MOA doit être la MOA principale",
299                     }
300                 }
301         ids = self.search(
302             cr,
303             uid,
304             [
305                 ('project_id', '=', project),
306                 ('moa_id', '!=', moa),
307             ],
308             context=context,
309         )
310         current_id = self.search(
311             cr,
312             uid,
313             [
314                 ('project_id', '=', project),
315                 ('moa_id', '=', moa),
316             ],
317             context=context,
318         )
319         self.write(cr, uid, ids, {'main': False}, context=context)
320         self.write(cr, uid, current_id, {'main': True}, context=context)
321
322         return {'value': {'main': True}}
323
324
325
326 class ProjetPhase(osv.Model):
327     _name = "cmmi.projet.phase"
328
329     _description = "Rattachement des Phases aux projets"
330
331     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
332         if isinstance(ids, (int, long)):
333             ids = [ids]
334         return dict([(i, r.phase_id.name) for i, r in
335                 zip(ids, self.browse(cr, uid, ids, context=context))])
336
337     _columns = {
338         "name": fields.function(_get_name,
339                                 type='char',
340                                 store=True,
341                                 string="Nom de la phase"),
342         "phase_id": fields.many2one("cmmi.phase",
343                                     string="Phase",
344                                     required=True),
345         "projet_id": fields.many2one("cmmi.projet",
346                                      string="Projet",
347                                      required=True),
348         "selectionne": fields.boolean(string="Phase sélectionnée ?"),
349     }
350
351
352
353 class ProjetTeammember(osv.Model):
354     _name = "cmmi.projet.teammember"
355
356     _description = "Rattachement des Team members a un projet."
357
358     def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
359         if isinstance(ids, (int, long)):
360             ids = [ids]
361         return dict([(i, r.partner_id.name) for i, r in
362                 zip(ids, self.browse(cr, uid, ids, context=context))])
363
364     def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
365         if isinstance(ids, (int, long)):
366             ids = [ids]
367         return dict([(i, r.projet_id.name) for i, r in
368                 zip(ids, self.browse(cr, uid, ids, context=context))])
369
370     _columns = {
371         "name": fields.function(_get_partner_name,
372                                 type='char',
373                                 store=True,
374                                 string="Nom du partner"),
375         "projet_name": fields.function(_get_project_name,
376                                        type='char',
377                                        store=True,
378                                        string="Nom du projet"),
379         "affecte": fields.integer(string="Affecté à"),
380         "depuis": fields.date(string="Depuis"),
381         "jusqua": fields.date(string="Jusqu'à"),
382         "projet_id": fields.many2one("cmmi.projet",
383                                      string="Projet",
384                                      required=True),
385         "partner_id": fields.many2one("res.partner",
386                                     string="Team Member",
387                                     required=True),
388     }