Ajout d'un champ charge_reel dans palier
[OpenERP/cmmi.git] / evolution.py
index 4921278..13917c3 100644 (file)
@@ -23,6 +23,27 @@ class Evolution(osv.Model):
                 ("termine", "Terminé"), ("abandonne", "Abandonné"),
                 ("suspendu", "Suspendu")]
 
+
+    def _get_charge_init(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for evo in self.browse(cr, uid, ids, context=context):
+            result[evo.id] = sum([p.charge_init for p in evo.phases])
+        return result
+
+
+    def _get_charge_plan(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for evo in self.browse(cr, uid, ids, context=context):
+            result[evo.id] = sum([p.charge_plan for p in evo.phases])
+        return result
+
+    def _get_charge_reel(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for e in self.browse(cr, uid, ids, context=context):
+            result[e.id] = sum([p.quantite for p in e.charge_reel])
+        return result
+
+
     _columns = {
         "pid": fields.integer(string="PID"),
         "name": fields.char(string="Title", size=64, required=True),
@@ -32,9 +53,9 @@ class Evolution(osv.Model):
         "keywords": fields.text(string="Mots clés"),
         "priorite": fields.selection(_priorites, string="Priorité"),
         "state": fields.selection(_statuts, string="Statut"),
-#        "charges": fields.one2many("cmmi.evolution.charge", # Supprimé !
-#                                   "evolution_id",
-#                                   string="Charges"),
+        "phases": fields.one2many("cmmi.evolution.phase",
+                                  "evolution_id",
+                                  string="Phases"),
         # Backrefs
         "module_id": fields.many2one("cmmi.description.module",
                                      string="Modules"),
@@ -47,6 +68,16 @@ class Evolution(osv.Model):
         "demandeur": fields.many2one("res.partner",
                                      string="Demandeur",
                                      domain=_domains['human']),
+        # Functions
+        "charge_init": fields.function(_get_charge_init,
+                                       type="integer",
+                                       string="Charge initiale"),
+        "charge_plan": fields.function(_get_charge_plan,
+                                       type="integer",
+                                       string="Charge plannifiée"),
+        "charge_reel": fields.function(_get_charge_reel,
+                                       type="integer",
+                                       string="Charge réelle"),
     }
 
     _defaults = {
@@ -166,6 +197,8 @@ class Phase(osv.Model):
                                 store=True,
                                 string="Nom de la phase"),
         "description": fields.text(string="Description"),
+        "charge_init": fields.integer(string="Charge initiale"),
+        "charge_plan": fields.integer(string="Charge plannifiée"),
         "phase_id": fields.many2one("cmmi.axes.palier.phase",
                                     string="Phase"),
         "evolution_id": fields.many2one("cmmi.evolution",
@@ -196,6 +229,23 @@ class Phase(osv.Model):
 
         return osv.Model.create(self, cr, uid, vals, context=context)
 
+    def commencer(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return
+            ids = ids[0]
+
+        phase = self.read(cr, uid, ids, ['charge_plan'], context)
+
+        self.write(
+            cr,
+            uid,
+            ids, {
+                'charge_init' : phase['charge_plan'],
+            },
+            context)
+        return self
+
 
 # =========================== EVOLUTION CHARGE ============================== #
 class Charge(osv.Model):
@@ -203,11 +253,15 @@ class Charge(osv.Model):
 
     _description = "Charge d'une evolution."
 
+    _selection_qte = [("0.25", "1/4"),
+                      ("0.5", "1/2"),
+                      ("0.75", "3/4")]
+
     _columns = {
         "name": fields.char(string="Title", size=64, required=True),
         "description": fields.text(string="Description"),
-        "evolution_id": fields.many2one("cmmi.evolution",
-                                        string="Palier"),
+        "date": fields.date(string="Date"),
+        "quantite": fields.selection(_selection_qte, string="Quantité"),
         "phase_id": fields.many2one("cmmi.evolution.phase",
                                     string="Phase de l'évolution",
                                     required=True),