5 from openerp.osv import osv, fields
8 class Projet(osv.Model):
12 _description = "Table des projets."
14 def _get_main_domain(self, cr, uid, ids, field_name=None, arg=None, context=None):
15 if type(ids) in (int, float):
18 projects = self.browse(cr, uid, ids, context=context)
22 for project in projects:
23 for domain in project.domains:
25 result[project.id] = domain.name
28 result[project.id] = "Any domain is selected as main domain yet"
33 def _get_main_moa(self, cr, uid, ids, field_name=None, arg=None, context=None):
34 if type(ids) in (int, float):
37 projects = self.browse(cr, uid, ids, context=context)
41 for project in projects:
42 for moa in project.moa_ids:
44 result[project.id] = moa.name
47 result[project.id] = "Any MOA is selected as main MOA yet"
52 def _get_main_moe(self, cr, uid, ids, field_name=None, arg=None, context=None):
53 if type(ids) in (int, float):
56 projects = self.browse(cr, uid, ids, context=context)
60 for project in projects:
61 for moe in project.moe_ids:
63 result[project.id] = moe.name
66 result[project.id] = "Any MOE is selected as main MOE yet"
70 def _get_phases_selectionnees(self, cr, uid, ids, field_name=None, arg=None, context=None):
72 for projet in self.browse(cr, uid, ids, context=context):
74 for phase in projet.phases:
75 #import pdb; pdb.set_trace()
78 result[projet.id] = res
83 "name": fields.char(string="Title", size=64, required=True),
84 "description": fields.text(string="Description"),
85 "use_chantier": fields.boolean(string="Utilisation de la notion de chantier ?"),
86 "use_palier": fields.boolean(string="Utilisation de la notion de palier ?"),
89 "domains": fields.one2many("cmmi.projet.domaine",
92 "moe_ids": fields.one2many("cmmi.projet.moe",
95 "moa_ids": fields.one2many("cmmi.projet.moa",
98 "team_members": fields.one2many("cmmi.projet.teammember",
100 string="Team Members"),
101 "modules": fields.one2many("cmmi.description.module",
104 "chantiers": fields.one2many("cmmi.axes.chantier",
107 "paliers": fields.one2many("cmmi.axes.palier",
110 "phases": fields.one2many("cmmi.projet.phase",
113 "evolutions": fields.one2many("cmmi.evolution",
115 string="Evolutions"),
117 # Champs fonction rapatriant les mo ou domaine principaux
118 "moe_id": fields.function(_get_main_moe,
120 string="MOE principale"),
121 "moa_id": fields.function(_get_main_moa,
123 string="MOA principale"),
124 "main_domain": fields.function(_get_main_domain,
126 string="Domaine principal"),
127 "phases_selectionnees": fields.function(_get_phases_selectionnees,
129 obj="cmmi.projet.phase",
130 string="Phases sélectionnées"),
134 "use_chantier": True,
139 def create(self, cr, uid, vals, context=None):
140 project_id = osv.Model.create(self, cr, uid, vals, context=context)
142 # Récupération des ids de toutes les phases
143 phase_model = self.pool.get("cmmi.phase")
144 phases_ids = phase_model.search(cr, uid, [])
146 # Création des relations
147 projet_phase_model = self.pool.get("cmmi.projet.phase")
148 for phase_id in phases_ids:
149 projet_phase_model.create(
153 'projet_id': project_id,
154 'phase_id': phase_id,
155 'selectionne': False,
162 def action_add_domain(self, cr, uid, ids, context=None):
165 def action_add_moe(self, cr, uid, ids, context=None):
168 def action_add_moa(self, cr, uid, ids, context=None):
173 class ProjetDomaine(osv.Model):
175 _name = "cmmi.projet.domaine"
177 _description = "Rattachement des domaines a un projet."
179 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
180 if isinstance(ids, (int, long)):
182 #return {i: r.domaine_id.name for i, r in
183 # zip(ids, self.browse(cr, uid, ids, context=context))}
184 return dict([(i, r.domaine_id.name) for i, r in
185 zip(ids, self.browse(cr, uid, ids, context=context))])
188 "name": fields.function(_get_name,
191 string="Nom du domaine"),
192 "main": fields.boolean(string="Domaine principal ?"),
193 "project_id": fields.many2one("cmmi.projet",
195 "domaine_id": fields.many2one("cmmi.description.domaine",
199 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
201 return {'value': {'main': True},
203 'title' : "Integrity Warning",
204 'message' : "One of the domains should be the main domain",
211 ('project_id', '=', project),
212 ('domaine_id', '!=', domaine),
216 current_id = self.search(
220 ('project_id', '=', project),
221 ('domaine_id', '=', domaine),
225 self.write(cr, uid, ids, {'main': False}, context=context)
226 self.write(cr, uid, current_id, {'main': True}, context=context)
228 return {'value': {'main': True}}
232 class ProjetMoe(osv.Model):
233 _name = "cmmi.projet.moe"
235 _description = "Rattachement des MOEs au projet."
237 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
238 if isinstance(ids, (int, long)):
240 return dict([(i, r.moe_id.name) for i, r in
241 zip(ids, self.browse(cr, uid, ids, context=context))])
244 "name": fields.function(_get_name,
246 store=True, # Permet d'enregistrer le champ.
247 string="Nom de la MOE"),
248 "main": fields.boolean(string="MOE principale ?"),
249 "project_id": fields.many2one("cmmi.projet",
252 "moe_id": fields.many2one("cmmi.mo.moe",
257 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
259 return {'value': {'main': True},
261 'title' : "Integrity Warning",
262 'message' : "Une des MOE doit être la MOE principale",
269 ('project_id', '=', project),
270 ('moe_id', '!=', moe),
274 current_id = self.search(
278 ('project_id', '=', project),
279 ('moe_id', '=', moe),
283 self.write(cr, uid, ids, {'main': False}, context=context)
284 self.write(cr, uid, current_id, {'main': True}, context=context)
286 return {'value': {'main': True}}
290 class ProjetMoa(osv.Model):
291 _name = "cmmi.projet.moa"
293 _description = "Rattachement des MOAs a une projet."
295 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
296 if isinstance(ids, (int, long)):
298 return dict([(i, r.moa_id.name) for i, r in
299 zip(ids, self.browse(cr, uid, ids, context=context))])
302 "name": fields.function(_get_name,
305 string="Nom de la MOA"),
306 "main": fields.boolean(string="MOA principale ?"),
307 "project_id": fields.many2one("cmmi.projet",
310 "moa_id": fields.many2one("cmmi.mo.moa",
315 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
317 return {'value': {'main': True},
319 'title' : "Integrity Warning",
320 'message' : "Une des MOA doit être la MOA principale",
327 ('project_id', '=', project),
328 ('moa_id', '!=', moa),
332 current_id = self.search(
336 ('project_id', '=', project),
337 ('moa_id', '=', moa),
341 self.write(cr, uid, ids, {'main': False}, context=context)
342 self.write(cr, uid, current_id, {'main': True}, context=context)
344 return {'value': {'main': True}}
348 class ProjetPhase(osv.Model):
349 _name = "cmmi.projet.phase"
351 _description = "Rattachement des Phases aux projets"
353 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
354 if isinstance(ids, (int, long)):
356 return dict([(i, r.phase_id.name) for i, r in
357 zip(ids, self.browse(cr, uid, ids, context=context))])
360 "name": fields.function(_get_name,
363 string="Nom de la phase"),
364 "phase_id": fields.many2one("cmmi.phase",
367 "projet_id": fields.many2one("cmmi.projet",
370 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
375 class ProjetTeammember(osv.Model):
376 _name = "cmmi.projet.teammember"
378 _description = "Rattachement des Team members a un projet."
380 def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
381 if isinstance(ids, (int, long)):
383 return dict([(i, r.partner_id.name) for i, r in
384 zip(ids, self.browse(cr, uid, ids, context=context))])
386 def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
387 if isinstance(ids, (int, long)):
389 return dict([(i, r.projet_id.name) for i, r in
390 zip(ids, self.browse(cr, uid, ids, context=context))])
393 "name": fields.function(_get_partner_name,
396 string="Nom du partner"),
397 "projet_name": fields.function(_get_project_name,
400 string="Nom du projet"),
401 "affecte": fields.integer(string="Affecté à"),
402 "depuis": fields.date(string="Depuis"),
403 "jusqua": fields.date(string="Jusqu'à"),
404 "projet_id": fields.many2one("cmmi.projet",
407 "partner_id": fields.many2one("res.partner",
408 string="Team Member",