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 def create(self, cr, uid, vals, context=None):
135 project_id = osv.Model.create(self, cr, uid, vals, context=context)
137 # Récupération des ids de toutes les phases
138 phase_model = self.pool.get("cmmi.phase")
139 phases_ids = phase_model.search(cr, uid, [])
141 # Création des relations
142 projet_phase_model = self.pool.get("cmmi.projet.phase")
143 for phase_id in phases_ids:
144 projet_phase_model.create(
148 'projet_id': project_id,
149 'phase_id': phase_id,
150 'selectionne': False,
157 def action_add_domain(self, cr, uid, ids, context=None):
160 def action_add_moe(self, cr, uid, ids, context=None):
163 def action_add_moa(self, cr, uid, ids, context=None):
168 class ProjetDomaine(osv.Model):
170 _name = "cmmi.projet.domaine"
172 _description = "Rattachement des domaines a un projet."
174 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
175 if isinstance(ids, (int, long)):
177 #return {i: r.domaine_id.name for i, r in
178 # zip(ids, self.browse(cr, uid, ids, context=context))}
179 return dict([(i, r.domaine_id.name) for i, r in
180 zip(ids, self.browse(cr, uid, ids, context=context))])
183 "name": fields.function(_get_name,
186 string="Nom du domaine"),
187 "main": fields.boolean(string="Domaine principal ?"),
188 "project_id": fields.many2one("cmmi.projet",
190 "domaine_id": fields.many2one("cmmi.description.domaine",
194 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
196 return {'value': {'main': True},
198 'title' : "Integrity Warning",
199 'message' : "One of the domains should be the main domain",
206 ('project_id', '=', project),
207 ('domaine_id', '!=', domaine),
211 current_id = self.search(
215 ('project_id', '=', project),
216 ('domaine_id', '=', domaine),
220 self.write(cr, uid, ids, {'main': False}, context=context)
221 self.write(cr, uid, current_id, {'main': True}, context=context)
223 return {'value': {'main': True}}
227 class ProjetMoe(osv.Model):
228 _name = "cmmi.projet.moe"
230 _description = "Rattachement des MOEs au projet."
232 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
233 if isinstance(ids, (int, long)):
235 return dict([(i, r.moe_id.name) for i, r in
236 zip(ids, self.browse(cr, uid, ids, context=context))])
239 "name": fields.function(_get_name,
241 store=True, # Permet d'enregistrer le champ.
242 string="Nom de la MOE"),
243 "main": fields.boolean(string="MOE principale ?"),
244 "project_id": fields.many2one("cmmi.projet",
247 "moe_id": fields.many2one("cmmi.mo.moe",
252 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
254 return {'value': {'main': True},
256 'title' : "Integrity Warning",
257 'message' : "Une des MOE doit être la MOE principale",
264 ('project_id', '=', project),
265 ('moe_id', '!=', moe),
269 current_id = self.search(
273 ('project_id', '=', project),
274 ('moe_id', '=', moe),
278 self.write(cr, uid, ids, {'main': False}, context=context)
279 self.write(cr, uid, current_id, {'main': True}, context=context)
281 return {'value': {'main': True}}
285 class ProjetMoa(osv.Model):
286 _name = "cmmi.projet.moa"
288 _description = "Rattachement des MOAs a une projet."
290 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
291 if isinstance(ids, (int, long)):
293 return dict([(i, r.moa_id.name) for i, r in
294 zip(ids, self.browse(cr, uid, ids, context=context))])
297 "name": fields.function(_get_name,
300 string="Nom de la MOA"),
301 "main": fields.boolean(string="MOA principale ?"),
302 "project_id": fields.many2one("cmmi.projet",
305 "moa_id": fields.many2one("cmmi.mo.moa",
310 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
312 return {'value': {'main': True},
314 'title' : "Integrity Warning",
315 'message' : "Une des MOA doit être la MOA principale",
322 ('project_id', '=', project),
323 ('moa_id', '!=', moa),
327 current_id = self.search(
331 ('project_id', '=', project),
332 ('moa_id', '=', moa),
336 self.write(cr, uid, ids, {'main': False}, context=context)
337 self.write(cr, uid, current_id, {'main': True}, context=context)
339 return {'value': {'main': True}}
343 class ProjetPhase(osv.Model):
344 _name = "cmmi.projet.phase"
346 _description = "Rattachement des Phases aux projets"
348 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
349 if isinstance(ids, (int, long)):
351 return dict([(i, r.phase_id.name) for i, r in
352 zip(ids, self.browse(cr, uid, ids, context=context))])
355 "name": fields.function(_get_name,
358 string="Nom de la phase"),
359 "phase_id": fields.many2one("cmmi.phase",
362 "projet_id": fields.many2one("cmmi.projet",
365 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
370 class ProjetTeammember(osv.Model):
371 _name = "cmmi.projet.teammember"
373 _description = "Rattachement des Team members a un projet."
375 def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
376 if isinstance(ids, (int, long)):
378 return dict([(i, r.partner_id.name) for i, r in
379 zip(ids, self.browse(cr, uid, ids, context=context))])
381 def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
382 if isinstance(ids, (int, long)):
384 return dict([(i, r.projet_id.name) for i, r in
385 zip(ids, self.browse(cr, uid, ids, context=context))])
388 "name": fields.function(_get_partner_name,
391 string="Nom du partner"),
392 "projet_name": fields.function(_get_project_name,
395 string="Nom du projet"),
396 "affecte": fields.integer(string="Affecté à"),
397 "depuis": fields.date(string="Depuis"),
398 "jusqua": fields.date(string="Jusqu'à"),
399 "projet_id": fields.many2one("cmmi.projet",
402 "partner_id": fields.many2one("res.partner",
403 string="Team Member",