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"),
86 "domains": fields.one2many("cmmi.projet.domaine",
89 "moe_ids": fields.one2many("cmmi.projet.moe",
92 "moa_ids": fields.one2many("cmmi.projet.moa",
95 "team_members": fields.one2many("cmmi.projet.teammember",
97 string="Team Members"),
98 "modules": fields.one2many("cmmi.description.module",
101 "chantiers": fields.one2many("cmmi.axes.chantier",
104 "paliers": fields.one2many("cmmi.axes.palier",
107 "phases": fields.one2many("cmmi.projet.phase",
110 "evolutions": fields.one2many("cmmi.evolution",
112 string="Evolutions"),
113 # TODO: faire un champs fonction qui renvoie uniquement les domaines sélectionnés
115 # Champs fonction rapatriant les mo ou domaine principaux
116 "moe_id": fields.function(_get_main_moe,
118 string="MOE principale"),
119 "moa_id": fields.function(_get_main_moa,
121 string="MOA principale"),
122 "main_domain": fields.function(_get_main_domain,
124 string="Domaine principal"),
125 "phases_selectionnees": fields.function(_get_phases_selectionnees,
127 obj="cmmi.projet.phase",
128 string="Phases sélectionnées"),
132 def create(self, cr, uid, vals, context=None):
133 project_id = osv.Model.create(self, cr, uid, vals, context=context)
135 # Récupération des ids de toutes les phases
136 phase_model = self.pool.get("cmmi.phase")
137 phases_ids = phase_model.search(cr, uid, [])
139 # Création des relations
140 projet_phase_model = self.pool.get("cmmi.projet.phase")
141 for phase_id in phases_ids:
142 projet_phase_model.create(
146 'projet_id': project_id,
147 'phase_id': phase_id,
148 'selectionne': False,
155 def action_add_domain(self, cr, uid, ids, context=None):
158 def action_add_moe(self, cr, uid, ids, context=None):
161 def action_add_moa(self, cr, uid, ids, context=None):
166 class ProjetDomaine(osv.Model):
168 _name = "cmmi.projet.domaine"
170 _description = "Rattachement des domaines a un projet."
172 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
173 if isinstance(ids, (int, long)):
175 #return {i: r.domaine_id.name for i, r in
176 # zip(ids, self.browse(cr, uid, ids, context=context))}
177 return dict([(i, r.domaine_id.name) for i, r in
178 zip(ids, self.browse(cr, uid, ids, context=context))])
181 "name": fields.function(_get_name,
184 string="Nom du domaine"),
185 "main": fields.boolean(string="Domaine principal ?"),
186 "project_id": fields.many2one("cmmi.projet",
188 "domaine_id": fields.many2one("cmmi.description.domaine",
192 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
194 return {'value': {'main': True},
196 'title' : "Integrity Warning",
197 'message' : "One of the domains should be the main domain",
204 ('project_id', '=', project),
205 ('domaine_id', '!=', domaine),
209 current_id = self.search(
213 ('project_id', '=', project),
214 ('domaine_id', '=', domaine),
218 self.write(cr, uid, ids, {'main': False}, context=context)
219 self.write(cr, uid, current_id, {'main': True}, context=context)
221 return {'value': {'main': True}}
225 class ProjetMoe(osv.Model):
226 _name = "cmmi.projet.moe"
228 _description = "Rattachement des MOEs au projet."
230 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
231 if isinstance(ids, (int, long)):
233 return dict([(i, r.moe_id.name) for i, r in
234 zip(ids, self.browse(cr, uid, ids, context=context))])
237 "name": fields.function(_get_name,
239 store=True, # Permet d'enregistrer le champ.
240 string="Nom de la MOE"),
241 "main": fields.boolean(string="MOE principale ?"),
242 "project_id": fields.many2one("cmmi.projet",
245 "moe_id": fields.many2one("cmmi.mo.moe",
250 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
252 return {'value': {'main': True},
254 'title' : "Integrity Warning",
255 'message' : "Une des MOE doit être la MOE principale",
262 ('project_id', '=', project),
263 ('moe_id', '!=', moe),
267 current_id = self.search(
271 ('project_id', '=', project),
272 ('moe_id', '=', moe),
276 self.write(cr, uid, ids, {'main': False}, context=context)
277 self.write(cr, uid, current_id, {'main': True}, context=context)
279 return {'value': {'main': True}}
283 class ProjetMoa(osv.Model):
284 _name = "cmmi.projet.moa"
286 _description = "Rattachement des MOAs a une projet."
288 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
289 if isinstance(ids, (int, long)):
291 return dict([(i, r.moa_id.name) for i, r in
292 zip(ids, self.browse(cr, uid, ids, context=context))])
295 "name": fields.function(_get_name,
298 string="Nom de la MOA"),
299 "main": fields.boolean(string="MOA principale ?"),
300 "project_id": fields.many2one("cmmi.projet",
303 "moa_id": fields.many2one("cmmi.mo.moa",
308 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
310 return {'value': {'main': True},
312 'title' : "Integrity Warning",
313 'message' : "Une des MOA doit être la MOA principale",
320 ('project_id', '=', project),
321 ('moa_id', '!=', moa),
325 current_id = self.search(
329 ('project_id', '=', project),
330 ('moa_id', '=', moa),
334 self.write(cr, uid, ids, {'main': False}, context=context)
335 self.write(cr, uid, current_id, {'main': True}, context=context)
337 return {'value': {'main': True}}
341 class ProjetPhase(osv.Model):
342 _name = "cmmi.projet.phase"
344 _description = "Rattachement des Phases aux projets"
346 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
347 if isinstance(ids, (int, long)):
349 return dict([(i, r.phase_id.name) for i, r in
350 zip(ids, self.browse(cr, uid, ids, context=context))])
353 "name": fields.function(_get_name,
356 string="Nom de la phase"),
357 "phase_id": fields.many2one("cmmi.phase",
360 "projet_id": fields.many2one("cmmi.projet",
363 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
368 class ProjetTeammember(osv.Model):
369 _name = "cmmi.projet.teammember"
371 _description = "Rattachement des Team members a un projet."
373 def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
374 if isinstance(ids, (int, long)):
376 return dict([(i, r.partner_id.name) for i, r in
377 zip(ids, self.browse(cr, uid, ids, context=context))])
379 def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
380 if isinstance(ids, (int, long)):
382 return dict([(i, r.projet_id.name) for i, r in
383 zip(ids, self.browse(cr, uid, ids, context=context))])
386 "name": fields.function(_get_partner_name,
389 string="Nom du partner"),
390 "projet_name": fields.function(_get_project_name,
393 string="Nom du projet"),
394 "affecte": fields.integer(string="Affecté à"),
395 "depuis": fields.date(string="Depuis"),
396 "jusqua": fields.date(string="Jusqu'à"),
397 "projet_id": fields.many2one("cmmi.projet",
400 "partner_id": fields.many2one("res.partner",
401 string="Team Member",