5 from openerp.osv import osv, fields
8 class Projet(osv.Model):
12 def _get_main_domain(self, cr, uid, ids, field_name=None, arg=None, context=None):
13 if type(ids) in (int, float):
16 projects = self.browse(cr, uid, ids, context=context)
20 for project in projects:
21 for domain in project.domains:
23 result[project.id] = domain.name
26 result[project.id] = "Any domain is selected as main domain yet"
31 def _get_main_moa(self, cr, uid, ids, field_name=None, arg=None, context=None):
32 if type(ids) in (int, float):
35 projects = self.browse(cr, uid, ids, context=context)
39 for project in projects:
40 for moa in project.moa_ids:
42 result[project.id] = moa.name
45 result[project.id] = "Any MOA is selected as main MOA yet"
50 def _get_main_moe(self, cr, uid, ids, field_name=None, arg=None, context=None):
51 if type(ids) in (int, float):
54 projects = self.browse(cr, uid, ids, context=context)
58 for project in projects:
59 for moe in project.moe_ids:
61 result[project.id] = moe.name
64 result[project.id] = "Any MOE is selected as main MOE yet"
70 "name": fields.char(string="Title", size=64, required=True),
71 "description": fields.text(string="Description"),
73 "domains": fields.one2many("cmmi.projet.domaine",
76 "moe_ids": fields.one2many("cmmi.projet.moe",
79 "moa_ids": fields.one2many("cmmi.projet.moa",
82 "team_members": fields.one2many("cmmi.projet.teammember",
84 string="Team Members"),
85 "modules": fields.one2many("cmmi.description.module",
88 "chantiers": fields.one2many("cmmi.axes.chantier",
91 "paliers": fields.one2many("cmmi.axes.palier",
94 "phases": fields.one2many("cmmi.projet.phase",
97 "evolutions": fields.one2many("cmmi.evolution",
100 # TODO: faire un champs fonction qui renvoie uniquement les domaines sélectionnés
102 # Champs fonction rapatriant les mo ou domaine principaux
103 "moe_id": fields.function(_get_main_moe,
105 string="MOE principale"),
106 "moa_id": fields.function(_get_main_moa,
108 string="MOA principale"),
109 "main_domain": fields.function(_get_main_domain,
111 string="Domaine principal"),
115 def create(self, cr, uid, vals, context=None):
116 project_id = osv.Model.create(self, cr, uid, vals, context=context)
118 # Récupération des ids de toutes les phases
119 phase_model = self.pool.get("cmmi.phase")
120 phases_ids = phase_model.search(cr, uid, [])
122 # Création des relations
123 projet_phase_model = self.pool.get("cmmi.projet.phase")
124 for phase_id in phases_ids:
125 projet_phase_model.create(
129 'projet_id': project_id,
130 'phase_id': phase_id,
131 'selectionne': False,
138 def action_add_domain(self, cr, uid, ids, context=None):
141 def action_add_moe(self, cr, uid, ids, context=None):
144 def action_add_moa(self, cr, uid, ids, context=None):
147 class ProjetDomaine(osv.Model):
149 _name = "cmmi.projet.domaine"
151 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
152 if isinstance(ids, (int, long)):
154 #return {i: r.domaine_id.name for i, r in
155 # zip(ids, self.browse(cr, uid, ids, context=context))}
156 return dict([(i, r.domaine_id.name) for i, r in
157 zip(ids, self.browse(cr, uid, ids, context=context))])
160 "name": fields.function(_get_name,
163 string="Nom du domaine"),
164 "main": fields.boolean(string="Domaine principal ?"),
165 "project_id": fields.many2one("cmmi.projet",
167 "domaine_id": fields.many2one("cmmi.description.domaine",
171 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
173 return {'value': {'main': True},
175 'title' : "Integrity Warning",
176 'message' : "One of the domains should be the main domain",
183 ('project_id', '=', project),
184 ('domaine_id', '!=', domaine),
188 current_id = self.search(
192 ('project_id', '=', project),
193 ('domaine_id', '=', domaine),
197 self.write(cr, uid, ids, {'main': False}, context=context)
198 self.write(cr, uid, current_id, {'main': True}, context=context)
200 return {'value': {'main': True}}
204 class ProjetMoe(osv.Model):
205 _name = "cmmi.projet.moe"
207 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
208 if isinstance(ids, (int, long)):
210 return dict([(i, r.moe_id.name) for i, r in
211 zip(ids, self.browse(cr, uid, ids, context=context))])
214 "name": fields.function(_get_name,
216 store=True, # Permet d'enregistrer le champ.
217 string="Nom de la MOE"),
218 "main": fields.boolean(string="MOE principale ?"),
219 "project_id": fields.many2one("cmmi.projet",
222 "moe_id": fields.many2one("cmmi.mo.moe",
227 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
229 return {'value': {'main': True},
231 'title' : "Integrity Warning",
232 'message' : "Une des MOE doit être la MOE principale",
239 ('project_id', '=', project),
240 ('moe_id', '!=', moe),
244 current_id = self.search(
248 ('project_id', '=', project),
249 ('moe_id', '=', moe),
253 self.write(cr, uid, ids, {'main': False}, context=context)
254 self.write(cr, uid, current_id, {'main': True}, context=context)
256 return {'value': {'main': True}}
259 class ProjetMoa(osv.Model):
260 _name = "cmmi.projet.moa"
262 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
263 if isinstance(ids, (int, long)):
265 return dict([(i, r.moa_id.name) for i, r in
266 zip(ids, self.browse(cr, uid, ids, context=context))])
269 "name": fields.function(_get_name,
272 string="Nom de la MOA"),
273 "main": fields.boolean(string="MOA principale ?"),
274 "project_id": fields.many2one("cmmi.projet",
277 "moa_id": fields.many2one("cmmi.mo.moa",
282 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
284 return {'value': {'main': True},
286 'title' : "Integrity Warning",
287 'message' : "Une des MOA doit être la MOA principale",
294 ('project_id', '=', project),
295 ('moa_id', '!=', moa),
299 current_id = self.search(
303 ('project_id', '=', project),
304 ('moa_id', '=', moa),
308 self.write(cr, uid, ids, {'main': False}, context=context)
309 self.write(cr, uid, current_id, {'main': True}, context=context)
311 return {'value': {'main': True}}
314 class ProjetPhase(osv.Model):
315 _name = "cmmi.projet.phase"
317 _description = "Rattachement des Phases aux projets"
319 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
320 if isinstance(ids, (int, long)):
322 return dict([(i, r.phase_id.name) for i, r in
323 zip(ids, self.browse(cr, uid, ids, context=context))])
326 "name": fields.function(_get_name,
329 string="Nom de la phase"),
330 "phase_id": fields.many2one("cmmi.phase",
333 "projet_id": fields.many2one("cmmi.projet",
336 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
340 class ProjetTeammember(osv.Model):
341 _name = "cmmi.projet.teammember"
343 def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
344 if isinstance(ids, (int, long)):
346 return dict([(i, r.partner_id.name) for i, r in
347 zip(ids, self.browse(cr, uid, ids, context=context))])
349 def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
350 if isinstance(ids, (int, long)):
352 return dict([(i, r.projet_id.name) for i, r in
353 zip(ids, self.browse(cr, uid, ids, context=context))])
356 "name": fields.function(_get_partner_name,
359 string="Nom du partner"),
360 "projet_name": fields.function(_get_project_name,
363 string="Nom du projet"),
364 "affecte": fields.integer(string="Affecté à"),
365 "depuis": fields.date(string="Depuis"),
366 "jusqua": fields.date(string="Jusqu'à"),
367 "projet_id": fields.many2one("cmmi.projet",
370 "partner_id": fields.many2one("res.partner",
371 string="Team Member",