Ajout d'un warning pour la fonction 'commencer' de Mesurable, à fixer
[OpenERP/cmmi.git] / axes.py
diff --git a/axes.py b/axes.py
index 7d638cb..6c73ba9 100644 (file)
--- a/axes.py
+++ b/axes.py
@@ -11,7 +11,7 @@ class Mesurable(osv.Model):
 
     _description = "Table de reference des mesusrables."
 
-    _statuts = [("cree", "Crée"), ("encours", "En cours"),
+    _states = [("cree", "Crée"), ("encours", "En cours"),
                 ("termine", "Terminé"), ("abandonne", "Abandonné"),
                 ("suspendu", "Suspendu"), ("generique", "Générique")]
 
@@ -30,7 +30,7 @@ class Mesurable(osv.Model):
         "name": fields.char(string="Title", size=64, required=True),
         "description": fields.text(string="Description"),
         "commentaire": fields.text(string="Commentaire"),
-        "statut": fields.selection(_statuts, string="Statut"),
+        "state": fields.selection(_states, string="State"),
         "version": fields.char(string="Version", size=16),
         "date_jalon": fields.date(string="Jalon"),
         "date_init_deb": fields.date(string="Init début"),
@@ -39,30 +39,134 @@ class Mesurable(osv.Model):
         "date_plan_fin": fields.date(string="Plan fin"),
         "date_reel_deb": fields.date(string="Réel début"),
         "date_reel_fin": fields.date(string="Réel fin"),
-        "nb_jours_projets": fields.function(_nb_jours_init,
+        "nb_jours_initial": fields.function(_nb_jours_init,
                                             type="integer",
                                             string="Nombre de jour"),
     }
 
+    _defaults = {
+        "state": "cree",
+    }
+
     _sql_constraints = [
         (
             "date_init_deb_before_date_init_fin",
-            "CHECK(date_init_deb<> date_init_fin)",
+            "CHECK(date_init_deb <= date_init_fin)",
             "The date_init_deb should be previous date_init_fin",
         ),
         (
             "date_plan_deb_before_date_plan_fin",
-            "CHECK(date_plan_deb <> date_plan_fin)",
+            "CHECK(date_plan_deb <= date_plan_fin)",
             "The date_plan_deb should be previous date_plan_fin",
         ),
         (
             "date_reel_deb_before_date_reel_fin",
-            "CHECK(date_reel_deb<> date_reel_fin)",
+            "CHECK(date_reel_deb <= date_reel_fin)",
             "The date_reel_deb should be previous date_reel_fin",
         ),
     ]
 
 
+    def commencer(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return
+            ids = ids[0]
+
+        palier = self.read(cr, uid, ids, ['date_plan_deb', 'date_plan_fin', 'state'], context)
+
+        if palier['state'] != 'cree':
+            return {
+                    'warning': { # FIXME: ne fonctionne pas
+                        'title'   : "Warning: not a list",
+                        'message' : "You cannot have negative number of seats",
+                        },
+                    }
+
+        self.write(
+            cr,
+            uid,
+            ids, {
+                'date_init_deb' : palier['date_plan_deb'],
+                'date_init_fin' : palier['date_plan_fin'],
+                'state': 'encours'
+            },
+            context)
+        return self
+
+
+    def suspendre(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        mesurable = self.read(cr, uid, ids, ['state'], context, context)
+        if mesurable['state'] != 'encours':
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'suspendu'},
+            context,
+        )
+        return self
+
+    def terminer(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        mesurable = self.read(cr, uid, ids, ['state'], context, context)
+        if mesurable['state'] != 'encours':
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'termine'},
+            context,
+        )
+        return self
+
+    def abandonner(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        mesurable = self.read(cr, uid, ids, ['state'], context, context)
+        if not ('encours', 'cree').__contains__(mesurable['state']):
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'abandonne'},
+            context,
+        )
+        return self
+
+    def reprendre(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        mesurable = self.read(cr, uid, ids, ['state'], context, context)
+        if mesurable['state'] != 'suspendu':
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'encours'},
+            context,
+        )
+        return self
+
 #------------ TRAVAIL CALCUL JOURS OUVRES ------------
     @staticmethod
     def _get_date_paques(annee):
@@ -171,6 +275,9 @@ class Palier(osv.Model):
         phase_model = self.pool.get("cmmi.projet.phase")
         phases_ids = phase_model.search(cr, uid, [('selectionne', '=', True)])
 
+        palier_model = self.pool.get("cmmi.axes.palier")
+        palier = palier_model.read(cr, uid, palier_id, ['date_plan_deb', 'date_plan_fin'])
+
         # Création des PalierPhase
         palier_phase_model = self.pool.get("cmmi.axes.palier.phase")
         for phase_id in phases_ids:
@@ -180,9 +287,10 @@ class Palier(osv.Model):
                 {
                     'phase_id': phase_id,
                     'palier_id': palier_id,
+                    'date_plan_deb': palier['date_plan_deb'],
+                    'date_plan_fin': palier['date_plan_fin'],
                 }
             )
-
         return palier_id
 
 
@@ -231,7 +339,6 @@ class PalierPhase(osv.Model):
         return osv.Model.create(self, cr, uid, vals, context=context)
 
 
-
 # ================================ CHANTIER ================================= #
 class Chantier(osv.Model):
     _name = "cmmi.axes.chantier"