Refonte de la notion de phase 3/3
authorSébastien CHAZALLET <s.chazallet@gmail.com>
Thu, 30 May 2013 11:14:46 +0000 (13:14 +0200)
committerSébastien CHAZALLET <s.chazallet@gmail.com>
Thu, 30 May 2013 11:14:46 +0000 (13:14 +0200)
axes.py
phase.py

diff --git a/axes.py b/axes.py
index 3236651..aa6ccf1 100644 (file)
--- a/axes.py
+++ b/axes.py
@@ -130,38 +130,83 @@ class Mesurable(osv.Model):
 #==============================================================================
 
 
-class Chantier(osv.Model):
-    _name = "cmmi.axes.chantier"
+class Palier(osv.Model):
+    _name = "cmmi.axes.palier"
+
+    _description = "Palier d'un projet."
 
     _inherit = "cmmi.axes.mesurable"
 
+    _types_palier = [("normal", "Normal"), ("exceptionnel", "Exceptionnel"),
+                     ("correctif", "Correctif"), ("autre", "Autre")]
+
     _columns = {
+        "type_palier": fields.selection(_types_palier, string="Type"),
         "projet_id": fields.many2one("cmmi.projet",
                                      string="Projet",
                                      required=True),
         "evolutions": fields.one2many("cmmi.evolution",
-                                      "chantier_id",
+                                      "palier_id",
                                       string="Evolutions"),
+        "phases": fields.one2many("cmmi.projet.phase",
+                                  "palier_id",
+                                  string="Phases"),
     }
 
 
-class Palier(osv.Model):
-    _name = "cmmi.axes.palier"
+class Phase(osv.Model):
+    _name = "cmmi.axes.palier.phase"
+
+    _description = "Step's phase / Phase d'un palier"
 
     _inherit = "cmmi.axes.mesurable"
 
-    _types_palier = [("normal", "Normal"), ("exceptionnel", "Exceptionnel"),
-                     ("correctif", "Correctif"), ("autre", "Autre")]
+    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"),
+        "phase_id": fields.many2one("cmmi.projet.phase",
+                                    string="Type phase"),
+        "palier_id": fields.many2one("cmmi.axes.palier",
+                                     string="Palier"),
+        # backrefs
+        "charges": fields.one2many("cmmi.evolution.charge",
+                                   "phase_id",
+                                   string="Charges"),
+        "evolutions": fields.one2many("cmmi.evolution",
+                                      "phase_id",
+                                      string="Evolutions"),
+    }
+
+    def create(self, cr, uid, vals, context=None):
+        # TODO: gérer la création d'une phase de palier.
+        # Vérifier les valeurs contenues dans vals et les modifier / rajouter si nécessaire selon les cas suivants
+
+        # Si description est vide, alors par défaut, recopie de la description du palier et de la phase (concaténés avec un retour à la ligne entre les deux).
+        # Si commentaire est vide, alors par défaut, recopie du commentaire du palier.
+        # Si version est vide, alors par dégaut, recopie de la version du palier.
+
+        return osv.Model.create(self, cr, uid, vals, context=context)
+
+
+class Chantier(osv.Model):
+    _name = "cmmi.axes.chantier"
+
+    _inherit = "cmmi.axes.mesurable"
 
     _columns = {
-        "type_palier": fields.selection(_types_palier, string="Type"),
         "projet_id": fields.many2one("cmmi.projet",
                                      string="Projet",
                                      required=True),
         "evolutions": fields.one2many("cmmi.evolution",
-                                      "palier_id",
+                                      "chantier_id",
                                       string="Evolutions"),
-        "phases": fields.one2many("cmmi.phase",
-                                  "palier_id",
-                                  string="Phases"),
     }
index ba6052f..05940a5 100644 (file)
--- a/phase.py
+++ b/phase.py
@@ -17,25 +17,3 @@ class Phase(osv.Model):
         "description": fields.text(string="Description"),
         "statut": fields.selection(_statuts, string="Statut"),
     }
-
-
-#class Phase(osv.Model):
-#    _name = "cmmi.phase"
-#
-#    _statuts = [("actif", "Actif"), ("inactif", "Inactif")]
-#
-#    _columns = {
-#        "name": fields.char(string="Title", size=64, required=True),
-#        "description": fields.text(string="Description"),
-#        "statut": fields.selection(_statuts, string="Statut"),
-#        "type_phase_id": fields.many2one("cmmi.phase.type",
-#                                         string="Type phase"),
-#        "charges": fields.one2many("cmmi.evolution.charge",
-#                                   "phase_id",
-#                                   string="Charges"),
-#        "evolutions": fields.one2many("cmmi.evolution",
-#                                      "phase_id",
-#                                      string="Evolutions"),
-#        "palier_id": fields.many2one("cmmi.axes.palier",
-#                                     string="Palier"),
-#    }