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"
72 "name": fields.char(string="Title", size=64, required=True),
73 "description": fields.text(string="Description"),
75 "domains": fields.one2many("cmmi.projet.domaine",
78 "moe_ids": fields.one2many("cmmi.projet.moe",
81 "moa_ids": fields.one2many("cmmi.projet.moa",
84 "team_members": fields.one2many("cmmi.projet.teammember",
86 string="Team Members"),
87 "modules": fields.one2many("cmmi.description.module",
90 "chantiers": fields.one2many("cmmi.axes.chantier",
93 "paliers": fields.one2many("cmmi.axes.palier",
96 "phases": fields.one2many("cmmi.projet.phase",
99 "evolutions": fields.one2many("cmmi.evolution",
101 string="Evolutions"),
102 # TODO: faire un champs fonction qui renvoie uniquement les domaines sélectionnés
104 # Champs fonction rapatriant les mo ou domaine principaux
105 "moe_id": fields.function(_get_main_moe,
107 string="MOE principale"),
108 "moa_id": fields.function(_get_main_moa,
110 string="MOA principale"),
111 "main_domain": fields.function(_get_main_domain,
113 string="Domaine principal"),
117 def create(self, cr, uid, vals, context=None):
118 project_id = osv.Model.create(self, cr, uid, vals, context=context)
120 # Récupération des ids de toutes les phases
121 phase_model = self.pool.get("cmmi.phase")
122 phases_ids = phase_model.search(cr, uid, [])
124 # Création des relations
125 projet_phase_model = self.pool.get("cmmi.projet.phase")
126 for phase_id in phases_ids:
127 projet_phase_model.create(
131 'projet_id': project_id,
132 'phase_id': phase_id,
133 'selectionne': False,
140 def action_add_domain(self, cr, uid, ids, context=None):
143 def action_add_moe(self, cr, uid, ids, context=None):
146 def action_add_moa(self, cr, uid, ids, context=None):
151 class ProjetDomaine(osv.Model):
153 _name = "cmmi.projet.domaine"
155 _description = "Rattachement des domaines a un projet."
157 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
158 if isinstance(ids, (int, long)):
160 #return {i: r.domaine_id.name for i, r in
161 # zip(ids, self.browse(cr, uid, ids, context=context))}
162 return dict([(i, r.domaine_id.name) for i, r in
163 zip(ids, self.browse(cr, uid, ids, context=context))])
166 "name": fields.function(_get_name,
169 string="Nom du domaine"),
170 "main": fields.boolean(string="Domaine principal ?"),
171 "project_id": fields.many2one("cmmi.projet",
173 "domaine_id": fields.many2one("cmmi.description.domaine",
177 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
179 return {'value': {'main': True},
181 'title' : "Integrity Warning",
182 'message' : "One of the domains should be the main domain",
189 ('project_id', '=', project),
190 ('domaine_id', '!=', domaine),
194 current_id = self.search(
198 ('project_id', '=', project),
199 ('domaine_id', '=', domaine),
203 self.write(cr, uid, ids, {'main': False}, context=context)
204 self.write(cr, uid, current_id, {'main': True}, context=context)
206 return {'value': {'main': True}}
210 class ProjetMoe(osv.Model):
211 _name = "cmmi.projet.moe"
213 _description = "Rattachement des MOEs au projet."
215 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
216 if isinstance(ids, (int, long)):
218 return dict([(i, r.moe_id.name) for i, r in
219 zip(ids, self.browse(cr, uid, ids, context=context))])
222 "name": fields.function(_get_name,
224 store=True, # Permet d'enregistrer le champ.
225 string="Nom de la MOE"),
226 "main": fields.boolean(string="MOE principale ?"),
227 "project_id": fields.many2one("cmmi.projet",
230 "moe_id": fields.many2one("cmmi.mo.moe",
235 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
237 return {'value': {'main': True},
239 'title' : "Integrity Warning",
240 'message' : "Une des MOE doit être la MOE principale",
247 ('project_id', '=', project),
248 ('moe_id', '!=', moe),
252 current_id = self.search(
256 ('project_id', '=', project),
257 ('moe_id', '=', moe),
261 self.write(cr, uid, ids, {'main': False}, context=context)
262 self.write(cr, uid, current_id, {'main': True}, context=context)
264 return {'value': {'main': True}}
268 class ProjetMoa(osv.Model):
269 _name = "cmmi.projet.moa"
271 _description = "Rattachement des MOAs a une projet."
273 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
274 if isinstance(ids, (int, long)):
276 return dict([(i, r.moa_id.name) for i, r in
277 zip(ids, self.browse(cr, uid, ids, context=context))])
280 "name": fields.function(_get_name,
283 string="Nom de la MOA"),
284 "main": fields.boolean(string="MOA principale ?"),
285 "project_id": fields.many2one("cmmi.projet",
288 "moa_id": fields.many2one("cmmi.mo.moa",
293 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
295 return {'value': {'main': True},
297 'title' : "Integrity Warning",
298 'message' : "Une des MOA doit être la MOA principale",
305 ('project_id', '=', project),
306 ('moa_id', '!=', moa),
310 current_id = self.search(
314 ('project_id', '=', project),
315 ('moa_id', '=', moa),
319 self.write(cr, uid, ids, {'main': False}, context=context)
320 self.write(cr, uid, current_id, {'main': True}, context=context)
322 return {'value': {'main': True}}
326 class ProjetPhase(osv.Model):
327 _name = "cmmi.projet.phase"
329 _description = "Rattachement des Phases aux projets"
331 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
332 if isinstance(ids, (int, long)):
334 return dict([(i, r.phase_id.name) for i, r in
335 zip(ids, self.browse(cr, uid, ids, context=context))])
338 "name": fields.function(_get_name,
341 string="Nom de la phase"),
342 "phase_id": fields.many2one("cmmi.phase",
345 "projet_id": fields.many2one("cmmi.projet",
348 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
353 class ProjetTeammember(osv.Model):
354 _name = "cmmi.projet.teammember"
356 _description = "Rattachement des Team members a un projet."
358 def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
359 if isinstance(ids, (int, long)):
361 return dict([(i, r.partner_id.name) for i, r in
362 zip(ids, self.browse(cr, uid, ids, context=context))])
364 def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
365 if isinstance(ids, (int, long)):
367 return dict([(i, r.projet_id.name) for i, r in
368 zip(ids, self.browse(cr, uid, ids, context=context))])
371 "name": fields.function(_get_partner_name,
374 string="Nom du partner"),
375 "projet_name": fields.function(_get_project_name,
378 string="Nom du projet"),
379 "affecte": fields.integer(string="Affecté à"),
380 "depuis": fields.date(string="Depuis"),
381 "jusqua": fields.date(string="Jusqu'à"),
382 "projet_id": fields.many2one("cmmi.projet",
385 "partner_id": fields.many2one("res.partner",
386 string="Team Member",