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"
51 "name": fields.char(string="Title", size=64, required=True),
52 "description": fields.text(string="Description"),
53 "domains": fields.one2many("cmmi.projet.domaine",
56 "team_members": fields.many2many("res.partner",
57 "cmmi_projet_teammember_rel",
60 string="Team Members"),
61 "modules": fields.one2many("cmmi.description.module",
64 "chantiers": fields.one2many("cmmi.axes.chantier",
67 "paliers": fields.one2many("cmmi.axes.palier",
70 "phases": fields.one2many("cmmi.projet.phase",
73 "evolutions": fields.one2many("cmmi.evolution",
76 "moe_ids": fields.one2many("cmmi.projet.moe",
79 "moa_ids": fields.one2many("cmmi.projet.moa",
82 "moe_id": fields.one2many("cmmi.projet.moe",
84 string="MOE principale",
85 domaine=[('main', '=', True)]),
86 "moa_id": fields.function(_get_main_moa,
88 string="MOA principale"),
89 "main_domain": fields.function(_get_main_domain,
91 string="Domaine principal"),
95 def create(self, cr, uid, vals, context=None):
96 project_id = osv.Model.create(self, cr, uid, vals, context=context)
98 # Récupération des ids de toutes les phases
99 phase_model = self.pool.get("cmmi.phase")
100 phases_ids = phase_model.search(cr, uid, [])
102 # Création des relations
103 projet_phase_model = self.pool.get("cmmi.projet.phase")
104 for phase_id in phases_ids:
105 projet_phase_model.create(
109 'projet_id': project_id,
110 'phase_id': phase_id,
111 'selectionne': False,
118 def action_add_domain(self, cr, uid, ids, context=None):
121 def action_add_moe(self, cr, uid, ids, context=None):
124 def action_add_moa(self, cr, uid, ids, context=None):
127 class ProjetDomaine(osv.Model):
129 _name = "cmmi.projet.domaine"
131 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
132 if isinstance(ids, (int, long)):
134 #return {i: r.domaine_id.name for i, r in
135 # zip(ids, self.browse(cr, uid, ids, context=context))}
136 return dict([(i, r.domaine_id.name) for i, r in
137 zip(ids, self.browse(cr, uid, ids, context=context))])
140 "name": fields.function(_get_name,
143 string="Nom du domaine"),
144 "main": fields.boolean(string="Domaine principal ?"),
145 "project_id": fields.many2one("cmmi.projet",
147 "domaine_id": fields.many2one("cmmi.description.domaine",
151 def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
153 return {'value': {'main': True},
155 'title' : "Integrity Warning",
156 'message' : "One of the domains should be the main domain",
163 ('project_id', '=', project),
164 ('domaine_id', '!=', domaine),
168 current_id = self.search(
172 ('project_id', '=', project),
173 ('domaine_id', '=', domaine),
177 self.write(cr, uid, ids, {'main': False}, context=context)
178 self.write(cr, uid, current_id, {'main': True}, context=context)
180 return {'value': {'main': True}}
184 class ProjetMoe(osv.Model):
185 _name = "cmmi.projet.moe"
187 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
188 if isinstance(ids, (int, long)):
190 return dict([(i, r.moe_id.name) for i, r in
191 zip(ids, self.browse(cr, uid, ids, context=context))])
194 "name": fields.function(_get_name,
196 store=True, # Permet d'enregistrer le champ.
197 string="Nom de la MOE"),
198 "main": fields.boolean(string="MOE principale ?"),
199 "project_id": fields.many2one("cmmi.projet",
202 "moe_id": fields.many2one("cmmi.mo.moe",
207 def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
211 class ProjetMoa(osv.Model):
212 _name = "cmmi.projet.moa"
214 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
215 if isinstance(ids, (int, long)):
217 return dict([(i, r.moa_id.name) for i, r in
218 zip(ids, self.browse(cr, uid, ids, context=context))])
221 "name": fields.function(_get_name,
224 string="Nom de la MOA"),
225 "main": fields.boolean(string="MOA principale ?"),
226 "project_id": fields.many2one("cmmi.projet",
229 "moa_id": fields.many2one("cmmi.mo.moa",
234 def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
236 return {'value': {'main': True},
238 'title' : "Integrity Warning",
239 'message' : "Une des MOA doit être la MOA principale",
246 ('project_id', '=', project),
247 ('moa_id', '!=', moa),
251 current_id = self.search(
255 ('project_id', '=', project),
256 ('moa_id', '=', moa),
260 self.write(cr, uid, ids, {'main': False}, context=context)
261 self.write(cr, uid, current_id, {'main': True}, context=context)
263 return {'value': {'main': True}}
266 class ProjetPhase(osv.Model):
267 _name = "cmmi.projet.phase"
269 def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
270 if isinstance(ids, (int, long)):
272 return dict([(i, r.phase_id.name) for i, r in
273 zip(ids, self.browse(cr, uid, ids, context=context))])
276 "name": fields.function(_get_name,
279 string="Nom de la phase"),
280 "selectionne": fields.boolean(string="Phase sélectionnée ?"),
281 "projet_id": fields.many2one("cmmi.projet",
284 "phase_id": fields.many2one("cmmi.phase",