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"),
114 # Champs fonction rapatriant les mo ou domaine principaux
115 "moe_id": fields.function(_get_main_moe,
117 string="MOE principale"),
118 "moa_id": fields.function(_get_main_moa,
120 string="MOA principale"),
121 "main_domain": fields.function(_get_main_domain,
123 string="Domaine principal"),
124 "phases_selectionnees": fields.function(_get_phases_selectionnees,
126 obj="cmmi.projet.phase",
127 string="Phases sélectionnées"),
131 def create(self, cr, uid, vals, context=None):
132 project_id = osv.Model.create(self, cr, uid, vals, context=context)
134 # Récupération des ids de toutes les phases
135 phase_model = self.pool.get("cmmi.phase")
136 phases_ids = phase_model.search(cr, uid, [])
138 # Création des relations
139 projet_phase_model = self.pool.get("cmmi.projet.phase")
140 for phase_id in phases_ids:
141 projet_phase_model.create(
145 'projet_id': project_id,
146 'phase_id': phase_id,
147 'selectionne': False,
154 def action_add_domain(self, cr, uid, ids, context=None):
157 def action_add_moe(self, cr, uid, ids, context=None):
160 def action_add_moa(self, cr, uid, ids, context=None):
165 class ProjetDomaine(osv.Model):
167 _name = "cmmi.projet.domaine"
169 _description = "Rattachement des domaines a un projet."
171 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
172 if isinstance(ids, (int, long)):
174 #return {i: r.domaine_id.name for i, r in
175 # zip(ids, self.browse(cr, uid, ids, context=context))}
176 return dict([(i, r.domaine_id.name) for i, r in
177 zip(ids, self.browse(cr, uid, ids, context=context))])
180 "name": fields.function(_get_name,
183 string="Nom du domaine"),
184 "main": fields.boolean(string="Domaine principal ?"),
185 "project_id": fields.many2one("cmmi.projet",
187 "domaine_id": fields.many2one("cmmi.description.domaine",
191 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
193 return {'value': {'main': True},
195 'title' : "Integrity Warning",
196 'message' : "One of the domains should be the main domain",
203 ('project_id', '=', project),
204 ('domaine_id', '!=', domaine),
208 current_id = self.search(
212 ('project_id', '=', project),
213 ('domaine_id', '=', domaine),
217 self.write(cr, uid, ids, {'main': False}, context=context)
218 self.write(cr, uid, current_id, {'main': True}, context=context)
220 return {'value': {'main': True}}
224 class ProjetMoe(osv.Model):
225 _name = "cmmi.projet.moe"
227 _description = "Rattachement des MOEs au projet."
229 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
230 if isinstance(ids, (int, long)):
232 return dict([(i, r.moe_id.name) for i, r in
233 zip(ids, self.browse(cr, uid, ids, context=context))])
236 "name": fields.function(_get_name,
238 store=True, # Permet d'enregistrer le champ.
239 string="Nom de la MOE"),
240 "main": fields.boolean(string="MOE principale ?"),
241 "project_id": fields.many2one("cmmi.projet",
244 "moe_id": fields.many2one("cmmi.mo.moe",
249 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
251 return {'value': {'main': True},
253 'title' : "Integrity Warning",
254 'message' : "Une des MOE doit être la MOE principale",
261 ('project_id', '=', project),
262 ('moe_id', '!=', moe),
266 current_id = self.search(
270 ('project_id', '=', project),
271 ('moe_id', '=', moe),
275 self.write(cr, uid, ids, {'main': False}, context=context)
276 self.write(cr, uid, current_id, {'main': True}, context=context)
278 return {'value': {'main': True}}
282 class ProjetMoa(osv.Model):
283 _name = "cmmi.projet.moa"
285 _description = "Rattachement des MOAs a une projet."
287 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
288 if isinstance(ids, (int, long)):
290 return dict([(i, r.moa_id.name) for i, r in
291 zip(ids, self.browse(cr, uid, ids, context=context))])
294 "name": fields.function(_get_name,
297 string="Nom de la MOA"),
298 "main": fields.boolean(string="MOA principale ?"),
299 "project_id": fields.many2one("cmmi.projet",
302 "moa_id": fields.many2one("cmmi.mo.moa",
307 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
309 return {'value': {'main': True},
311 'title' : "Integrity Warning",
312 'message' : "Une des MOA doit être la MOA principale",
319 ('project_id', '=', project),
320 ('moa_id', '!=', moa),
324 current_id = self.search(
328 ('project_id', '=', project),
329 ('moa_id', '=', moa),
333 self.write(cr, uid, ids, {'main': False}, context=context)
334 self.write(cr, uid, current_id, {'main': True}, context=context)
336 return {'value': {'main': True}}
340 class ProjetPhase(osv.Model):
341 _name = "cmmi.projet.phase"
343 _description = "Rattachement des Phases aux projets"
345 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
346 if isinstance(ids, (int, long)):
348 return dict([(i, r.phase_id.name) for i, r in
349 zip(ids, self.browse(cr, uid, ids, context=context))])
352 "name": fields.function(_get_name,
355 string="Nom de la phase"),
356 "phase_id": fields.many2one("cmmi.phase",
359 "projet_id": fields.many2one("cmmi.projet",
362 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
367 class ProjetTeammember(osv.Model):
368 _name = "cmmi.projet.teammember"
370 _description = "Rattachement des Team members a un projet."
372 def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
373 if isinstance(ids, (int, long)):
375 return dict([(i, r.partner_id.name) for i, r in
376 zip(ids, self.browse(cr, uid, ids, context=context))])
378 def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
379 if isinstance(ids, (int, long)):
381 return dict([(i, r.projet_id.name) for i, r in
382 zip(ids, self.browse(cr, uid, ids, context=context))])
385 "name": fields.function(_get_partner_name,
388 string="Nom du partner"),
389 "projet_name": fields.function(_get_project_name,
392 string="Nom du projet"),
393 "affecte": fields.integer(string="Affecté à"),
394 "depuis": fields.date(string="Depuis"),
395 "jusqua": fields.date(string="Jusqu'à"),
396 "projet_id": fields.many2one("cmmi.projet",
399 "partner_id": fields.many2one("res.partner",
400 string="Team Member",