Mesurable : changement du champ 'statut' en 'state'
[OpenERP/cmmi.git] / axes.py
diff --git a/axes.py b/axes.py
index 21fb17c..a48e86a 100644 (file)
--- a/axes.py
+++ b/axes.py
@@ -5,13 +5,13 @@
 from openerp.osv import osv, fields
 from datetime import date, timedelta, datetime
 
-
+# ================================ MESURABLE ================================ #
 class Mesurable(osv.Model):
     _name = "cmmi.axes.mesurable"
 
     _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"),
@@ -44,27 +44,72 @@ class Mesurable(osv.Model):
                                             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",
         ),
     ]
 
 
-#==================== TRAVAIL CALCUL JOURS OUVRES =============================
+    def commencer(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        palier = self.read(cr, uid, ids, ['date_plan_deb', 'date_plan_fin', 'state'], context)
+
+        if palier['state'] != 'cree':
+            return
+
+        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,
+        )
+
+
+
+#------------ TRAVAIL CALCUL JOURS OUVRES ------------
     @staticmethod
     def _get_date_paques(annee):
         """
@@ -134,9 +179,9 @@ class Mesurable(osv.Model):
             tmp += timedelta(days=1)
         return jour_ouvres
 
-#==============================================================================
 
 
+# ================================= PALIER ================================== #
 class Palier(osv.Model):
     _name = "cmmi.axes.palier"
 
@@ -160,6 +205,10 @@ class Palier(osv.Model):
                                   string="Phases"),
     }
 
+    _defaults = {
+        "type_palier": "normal",
+    }
+
 
     def create(self, cr, uid, vals, context=None):
         palier_id = osv.Model.create(self, cr, uid, vals, context=context)
@@ -179,11 +228,11 @@ class Palier(osv.Model):
                     'palier_id': palier_id,
                 }
             )
-
         return palier_id
 
 
 
+# =============================== PALIER-PHASE ============================== #
 class PalierPhase(osv.Model):
     _name = "cmmi.axes.palier.phase"
 
@@ -227,6 +276,8 @@ class PalierPhase(osv.Model):
         return osv.Model.create(self, cr, uid, vals, context=context)
 
 
+
+# ================================ CHANTIER ================================= #
 class Chantier(osv.Model):
     _name = "cmmi.axes.chantier"