+ string="MOA",
+ required=True),
+ }
+
+ def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
+ if not main:
+ return {'value': {'main': True},
+ 'warning': {
+ 'title' : "Integrity Warning",
+ 'message' : "Une des MOA doit être la MOA principale",
+ }
+ }
+ ids = self.search(
+ cr,
+ uid,
+ [
+ ('project_id', '=', project),
+ ('moa_id', '!=', moa),
+ ],
+ context=context,
+ )
+ current_id = self.search(
+ cr,
+ uid,
+ [
+ ('project_id', '=', project),
+ ('moa_id', '=', moa),
+ ],
+ context=context,
+ )
+ self.write(cr, uid, ids, {'main': False}, context=context)
+ self.write(cr, uid, current_id, {'main': True}, context=context)
+
+ return {'value': {'main': True}}
+
+
+
+# =============================== PROJET PHASE ============================== #
+class ProjetPhase(osv.Model):
+ _name = "cmmi.projet.phase"
+
+ _description = "Rattachement des Phases aux projets"
+
+ _columns = {
+ "name": fields.related("phase_id",
+ "name",
+ read_only=True,
+ type="char",
+ relation="cmmi.phase",
+ string="Nom de la phase"),
+ "phase_id": fields.many2one("cmmi.phase",
+ string="Phase",
+ required=True),
+ "projet_id": fields.many2one("cmmi.projet",
+ string="Projet",
+ required=True),
+ "selectionne": fields.boolean(string="Phase sélectionnée ?"),
+ }
+
+
+
+# ============================ PROJET TEAM MEMBER =========================== #
+class ProjetTeammember(osv.Model):
+ _name = "cmmi.projet.teammember"
+
+ _description = "Rattachement des Team members a un projet."
+
+ def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+ if isinstance(ids, (int, long)):
+ ids = [ids]
+ return dict([(i, r.partner_id.name) for i, r in
+ zip(ids, self.browse(cr, uid, ids, context=context))])
+
+ def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+ if isinstance(ids, (int, long)):
+ ids = [ids]
+ return dict([(i, r.projet_id.name) for i, r in
+ zip(ids, self.browse(cr, uid, ids, context=context))])
+
+ _columns = {
+ "name": fields.function(_get_partner_name,
+ type='char',
+ store=True,
+ string="Nom du partner"),
+ "projet_name": fields.function(_get_project_name,
+ type='char',
+ store=True,
+ string="Nom du projet"),
+ "affecte": fields.integer(string="Affecté à"),
+ "depuis": fields.date(string="Depuis"),
+ "jusqua": fields.date(string="Jusqu'à"),
+ "projet_id": fields.many2one("cmmi.projet",
+ string="Projet",
+ required=True),
+ "partner_id": fields.many2one("res.partner",
+ string="Team Member",
+ required=True),
+ }