Ajout de création de relations projet/phase lors de la création d'un projet
[OpenERP/cmmi.git] / projet.py
index 39b2327..98e9dfa 100644 (file)
--- a/projet.py
+++ b/projet.py
@@ -42,7 +42,7 @@ class Projet(osv.Model):
         "paliers": fields.one2many("cmmi.axes.palier",
                                    "projet_id",
                                    string="Paliers"),
-        "phases": fields.one2many("cmmi.phase",
+        "phases": fields.one2many("cmmi.projet.phase",
                                   "projet_id",
                                   string="Phases"),
         "evolutions": fields.one2many("cmmi.evolution",
@@ -56,9 +56,38 @@ class Projet(osv.Model):
                                           string="Structure principale"),
     }
 
+    def create(self, cr, uid, vals, context=None):
+        project_id = osv.Model.create(self, cr, uid, vals, context=context)
+
+        # Récupération des ids de toutes les phases
+        phase_model = self.pool.get("cmmi.phase")
+        phases_ids = phase_model.search(cr, uid, [])
+
+        # Création des relations
+        projet_phase_model = self.pool.get("cmmi.projet.phase")
+        for phase_id in phases_ids:
+            projet_phase_model.create(
+                cr,
+                uid,
+                {
+                    'projet_id': project_id,
+                    'phase_id': phase_id,
+                    'selectionne': False,
+                }
+            )
+
+        return project_id
+
+
     def action_add_domain(self, cr, uid, ids, context=None):
         pass
 
+    def action_add_moe(self, cr, uid, ids, context=None):
+        pass
+
+    def action_add_moa(self, cr, uid, ids, context=None):
+        pass
+
 class ProjetDomaine(osv.Model):
 
     _name = "cmmi.projet.domaine"
@@ -113,3 +142,76 @@ class ProjetDomaine(osv.Model):
         self.write(cr, uid, current_id, {'main': True}, context=context)
 
         return {'value': {'main': True}}
+
+
+
+class ProjetMoe(osv.Model):
+    _name = "cmmi.projet.moe"
+
+    def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if isinstance(ids, (int, long)):
+            ids = [ids]
+        return dict([(i, r.moe_id.name) for i, r in
+                zip(ids, self.browse(cr, uid, ids, context=context))])
+
+    _columns = {
+        "name": fields.function(_get_name,
+                                type='char',
+                                store=True, # Permet d'enregistrer le champ.
+                                string="Nom de la MOE"),
+        "main": fields.boolean(string="MOE principale ?"),
+        "project_id": fields.many2one("cmmi.projet",
+                                      string="Projet",
+                                      required=True),
+        "moe_id": fields.many2one("cmmi.mo.moe",
+                                  string="MOE",
+                                  required=True),
+    }
+
+
+class ProjetMoa(osv.Model):
+    _name = "cmmi.projet.moe"
+
+    def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if isinstance(ids, (int, long)):
+            ids = [ids]
+        return dict([(i, r.moa_id.name) for i, r in
+                zip(ids, self.browse(cr, uid, ids, context=context))])
+
+    _columns = {
+        "name": fields.function(_get_name,
+                                type='char',
+                                store=True,
+                                string="Nom de la MOA"),
+        "main": fields.boolean(string="MOA principale ?"),
+        "project_id": fields.many2one("cmmi.projet",
+                                      string="Projet",
+                                      required=True),
+        "moa_id": fields.many2one("cmmi.mo.moa",
+                                  string="MOA",
+                                  required=True),
+    }
+
+
+class ProjetPhase(osv.Model):
+    _name = "cmmi.projet.phase"
+
+    def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if isinstance(ids, (int, long)):
+            ids = [ids]
+        return dict([(i, r.phase_id.name) for i, r in
+                zip(ids, self.browse(cr, uid, ids, context=context))])
+
+    _columns = {
+        "name": fields.function(_get_name,
+                                type='char',
+                                store=True,
+                                string="Nom de la phase"),
+        "selectionne": fields.boolean(string="Phase sélectionnée ?"),
+        "projet_id": fields.many2one("cmmi.projet",
+                                     string="Projet",
+                                     required=True),
+        "phase_id": fields.many2one("cmmi.phase",
+                                    string="Phase",
+                                    required=True),
+    }
\ No newline at end of file