5 from openerp.osv import osv, fields
8 # ================================== PROJET ================================= #
9 class Projet(osv.Model):
13 _description = "Table des projets."
15 def _get_main_domain(self, cr, uid, ids, field_name=None, arg=None, context=None):
16 if type(ids) in (int, float):
19 projects = self.browse(cr, uid, ids, context=context)
23 for project in projects:
24 for domain in project.domains:
26 result[project.id] = domain.name
29 result[project.id] = "Any domain is selected as main domain yet"
34 def _get_main_moa(self, cr, uid, ids, field_name=None, arg=None, context=None):
35 if type(ids) in (int, float):
38 projects = self.browse(cr, uid, ids, context=context)
42 for project in projects:
43 for moa in project.moa_ids:
45 result[project.id] = moa.name
48 result[project.id] = "Any MOA is selected as main MOA yet"
53 def _get_main_moe(self, cr, uid, ids, field_name=None, arg=None, context=None):
54 if type(ids) in (int, float):
57 projects = self.browse(cr, uid, ids, context=context)
61 for project in projects:
62 for moe in project.moe_ids:
64 result[project.id] = moe.name
67 result[project.id] = "Any MOE is selected as main MOE yet"
71 def _get_phases_selectionnees(self, cr, uid, ids, field_name=None, arg=None, context=None):
73 for projet in self.browse(cr, uid, ids, context=context):
75 for phase in projet.phases:
76 #import pdb; pdb.set_trace()
79 result[projet.id] = res
84 "name": fields.char(string="Title", size=64, required=True),
85 "description": fields.text(string="Description"),
86 "use_chantier": fields.boolean(string="Utilisation de la notion de chantier ?"),
87 "use_palier": fields.boolean(string="Utilisation de la notion de palier ?"),
90 "domains": fields.one2many("cmmi.projet.domaine",
93 "moe_ids": fields.one2many("cmmi.projet.moe",
96 "moa_ids": fields.one2many("cmmi.projet.moa",
99 "team_members": fields.one2many("cmmi.projet.teammember",
101 string="Team Members"),
102 "modules": fields.one2many("cmmi.description.module",
105 "chantiers": fields.one2many("cmmi.axes.chantier",
108 "paliers": fields.one2many("cmmi.axes.palier",
111 "phases": fields.one2many("cmmi.projet.phase",
114 "evolutions": fields.one2many("cmmi.evolution",
116 string="Evolutions"),
118 # Champs fonction rapatriant les mo ou domaine principaux
119 "moe_id": fields.function(_get_main_moe,
121 string="MOE principale"),
122 "moa_id": fields.function(_get_main_moa,
124 string="MOA principale"),
125 "main_domain": fields.function(_get_main_domain,
127 string="Domaine principal"),
128 "phases_selectionnees": fields.function(_get_phases_selectionnees,
130 obj="cmmi.projet.phase",
131 string="Phases sélectionnées"),
135 "use_chantier": True,
140 def create(self, cr, uid, vals, context=None):
141 project_id = osv.Model.create(self, cr, uid, vals, context=context)
143 # Récupération des ids de toutes les phases
144 phase_model = self.pool.get("cmmi.phase")
145 phases_ids = phase_model.search(cr, uid, [])
147 # Création des relations
148 projet_phase_model = self.pool.get("cmmi.projet.phase")
149 for phase_id in phases_ids:
150 projet_phase_model.create(
154 'projet_id': project_id,
155 'phase_id': phase_id,
156 'selectionne': False,
163 def action_add_domain(self, cr, uid, ids, context=None):
166 def action_add_moe(self, cr, uid, ids, context=None):
169 def action_add_moa(self, cr, uid, ids, context=None):
174 # ============================= PROJET DOMAINE ============================== #
175 class ProjetDomaine(osv.Model):
177 _name = "cmmi.projet.domaine"
179 _description = "Rattachement des domaines a un projet."
181 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
182 if isinstance(ids, (int, long)):
184 #return {i: r.domaine_id.name for i, r in
185 # zip(ids, self.browse(cr, uid, ids, context=context))}
186 return dict([(i, r.domaine_id.name) for i, r in
187 zip(ids, self.browse(cr, uid, ids, context=context))])
190 "name": fields.function(_get_name,
193 string="Nom du domaine"),
194 "main": fields.boolean(string="Domaine principal ?"),
195 "project_id": fields.many2one("cmmi.projet",
197 "domaine_id": fields.many2one("cmmi.description.domaine",
201 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
203 return {'value': {'main': True},
205 'title' : "Integrity Warning",
206 'message' : "One of the domains should be the main domain",
213 ('project_id', '=', project),
214 ('domaine_id', '!=', domaine),
218 current_id = self.search(
222 ('project_id', '=', project),
223 ('domaine_id', '=', domaine),
227 self.write(cr, uid, ids, {'main': False}, context=context)
228 self.write(cr, uid, current_id, {'main': True}, context=context)
230 return {'value': {'main': True}}
234 # =============================== PROJET MOE ================================ #
235 class ProjetMoe(osv.Model):
236 _name = "cmmi.projet.moe"
238 _description = "Rattachement des MOEs au projet."
240 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
241 if isinstance(ids, (int, long)):
243 return dict([(i, r.moe_id.name) for i, r in
244 zip(ids, self.browse(cr, uid, ids, context=context))])
247 "name": fields.function(_get_name,
249 store=True, # Permet d'enregistrer le champ.
250 string="Nom de la MOE"),
251 "main": fields.boolean(string="MOE principale ?"),
252 "project_id": fields.many2one("cmmi.projet",
255 "moe_id": fields.many2one("cmmi.mo.moe",
260 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
262 return {'value': {'main': True},
264 'title' : "Integrity Warning",
265 'message' : "Une des MOE doit être la MOE principale",
272 ('project_id', '=', project),
273 ('moe_id', '!=', moe),
277 current_id = self.search(
281 ('project_id', '=', project),
282 ('moe_id', '=', moe),
286 self.write(cr, uid, ids, {'main': False}, context=context)
287 self.write(cr, uid, current_id, {'main': True}, context=context)
289 return {'value': {'main': True}}
293 # =============================== PROJET MOA ================================ #
294 class ProjetMoa(osv.Model):
295 _name = "cmmi.projet.moa"
297 _description = "Rattachement des MOAs a une projet."
299 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
300 if isinstance(ids, (int, long)):
302 return dict([(i, r.moa_id.name) for i, r in
303 zip(ids, self.browse(cr, uid, ids, context=context))])
306 "name": fields.function(_get_name,
309 string="Nom de la MOA"),
310 "main": fields.boolean(string="MOA principale ?"),
311 "project_id": fields.many2one("cmmi.projet",
314 "moa_id": fields.many2one("cmmi.mo.moa",
319 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
321 return {'value': {'main': True},
323 'title' : "Integrity Warning",
324 'message' : "Une des MOA doit être la MOA principale",
331 ('project_id', '=', project),
332 ('moa_id', '!=', moa),
336 current_id = self.search(
340 ('project_id', '=', project),
341 ('moa_id', '=', moa),
345 self.write(cr, uid, ids, {'main': False}, context=context)
346 self.write(cr, uid, current_id, {'main': True}, context=context)
348 return {'value': {'main': True}}
352 # =============================== PROJET PHASE ============================== #
353 class ProjetPhase(osv.Model):
354 _name = "cmmi.projet.phase"
356 _description = "Rattachement des Phases aux projets"
359 "name": fields.related("phase_id",
363 relation="cmmi.phase",
364 string="Nom de la phase"),
365 "phase_id": fields.many2one("cmmi.phase",
368 "projet_id": fields.many2one("cmmi.projet",
371 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
376 # ============================ PROJET TEAM MEMBER =========================== #
377 class ProjetTeammember(osv.Model):
378 _name = "cmmi.projet.teammember"
380 _description = "Rattachement des Team members a un projet."
382 def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
383 if isinstance(ids, (int, long)):
385 return dict([(i, r.partner_id.name) for i, r in
386 zip(ids, self.browse(cr, uid, ids, context=context))])
388 def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
389 if isinstance(ids, (int, long)):
391 return dict([(i, r.projet_id.name) for i, r in
392 zip(ids, self.browse(cr, uid, ids, context=context))])
395 "name": fields.function(_get_partner_name,
398 string="Nom du partner"),
399 "projet_name": fields.function(_get_project_name,
402 string="Nom du projet"),
403 "affecte": fields.integer(string="Affecté à"),
404 "depuis": fields.date(string="Depuis"),
405 "jusqua": fields.date(string="Jusqu'à"),
406 "projet_id": fields.many2one("cmmi.projet",
409 "partner_id": fields.many2one("res.partner",
410 string="Team Member",