Rajout champs calculés charge_init et charge_plan pour palier, chantier et palier_phase
authorAlicia FLOREZ <alicflorez@gmail.com>
Thu, 13 Jun 2013 14:42:43 +0000 (16:42 +0200)
committerAlicia FLOREZ <alicflorez@gmail.com>
Thu, 13 Jun 2013 14:42:43 +0000 (16:42 +0200)
axes.py
views/chantier.xml
views/palier.xml

diff --git a/axes.py b/axes.py
index 99e74a1..eeb2073 100644 (file)
--- a/axes.py
+++ b/axes.py
@@ -51,6 +51,7 @@ class Mesurable(osv.Model):
                         datetime.strptime(m.date_reel_fin, "%Y-%m-%d").date())
         return result
 
+
     _columns = {
         "name": fields.char(string="Title", size=64, required=True),
         "description": fields.text(string="Description"),
@@ -65,14 +66,14 @@ class Mesurable(osv.Model):
         "date_reel_deb": fields.date(string="Réel début"),
         "date_reel_fin": fields.date(string="Réel fin"),
         "nb_jours_init": fields.function(_nb_jours_init,
-                                            type="integer",
-                                            string="Nombre de jours initials"),
+                                         type="integer",
+                                         string="Nombre de jours initials"),
         "nb_jours_plan": fields.function(_nb_jours_plan,
-                                            type="integer",
-                                            string="Nombre de jours planifiés"),
+                                         type="integer",
+                                         string="Nombre de jours planifiés"),
         "nb_jours_reel": fields.function(_nb_jours_reel,
-                                            type="integer",
-                                            string="Nombre de jours réels"),
+                                         type="integer",
+                                         string="Nombre de jours réels"),
     }
 
     _defaults = {
@@ -276,6 +277,21 @@ class Palier(osv.Model):
     _types_palier = [("normal", "Normal"), ("exceptionnel", "Exceptionnel"),
                      ("correctif", "Correctif"), ("autre", "Autre")]
 
+
+    def _get_charge_init(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for palier in self.browse(cr, uid, ids, context=context):
+            result[palier.id] = sum([e.charge_init for e in palier.evolutions])
+        return result
+
+
+    def _get_charge_plan(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for palier in self.browse(cr, uid, ids, context=context):
+            result[palier.id] = sum([e.charge_plan for e in palier.evolutions])
+        return result
+
+
     _columns = {
         "type_palier": fields.selection(_types_palier, string="Type"),
         "projet_id": fields.many2one("cmmi.projet",
@@ -287,6 +303,12 @@ class Palier(osv.Model):
         "phases": fields.one2many("cmmi.axes.palier.phase",
                                   "palier_id",
                                   string="Phases"),
+        "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"),
     }
 
     _defaults = {
@@ -336,6 +358,20 @@ class PalierPhase(osv.Model):
                 zip(ids, self.browse(cr, uid, ids, context=context))])
 
 
+    def _get_charge_init(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for pp in self.browse(cr, uid, ids, context=context):
+            result[pp.id] = sum([p.charge_init for p in pp.phases])
+        return result
+
+
+    def _get_charge_plan(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for pp in self.browse(cr, uid, ids, context=context):
+            result[pp.id] = sum([p.charge_plan for p in pp.phases])
+        return result
+
+
     _columns = {
         "name": fields.function(_get_name,
                                 type='char',
@@ -349,6 +385,9 @@ class PalierPhase(osv.Model):
         "charges": fields.one2many("cmmi.evolution.charge",
                                    "phase_id",
                                    string="Charges"),
+        "phases": fields.one2many("cmmi.evolution.phase",
+                                  "phase_id",
+                                  string="Phases"),
 #        "evolutions": fields.one2many("cmmi.evolution", #Supprimé !
 #                                      "phase_id",
 #                                      string="Evolutions"),
@@ -373,6 +412,21 @@ class Chantier(osv.Model):
 
     _inherit = "cmmi.axes.mesurable"
 
+
+    def _get_charge_init(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for chantier in self.browse(cr, uid, ids, context=context):
+            result[chantier.id] = sum([e.charge_init for e in chantier.evolutions])
+        return result
+
+
+    def _get_charge_plan(self, cr, uid, ids, field, arg, context=None):
+        result = {}
+        for chantier in self.browse(cr, uid, ids, context=context):
+            result[chantier.id] = sum([e.charge_plan for e in chantier.evolutions])
+        return result
+
+
     _columns = {
         "projet_id": fields.many2one("cmmi.projet",
                                      string="Projet",
@@ -385,4 +439,10 @@ class Chantier(osv.Model):
         "evolutions": fields.one2many("cmmi.evolution",
                                       "chantier_id",
                                       string="Evolutions"),
+        "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"),
     }
index f8d9364..90bdd3d 100644 (file)
                                     <field name="date_reel_deb" colspan="1" nolabel="1" />
                                     <label for="date_reel_fin" colspan="1" />
                                     <field name="date_reel_fin" colspan="3" nolabel="1" />
+                                    <label for="charge_init" colspan="1" />
+                                    <field name="charge_init" colspan="2" nolabel="1" />
+                                    <label for="charge_plan" colspan="1" />
+                                    <field name="charge_plan" colspan="2" nolabel="1" />
                                 </group>
                             </page>
                             <page string="Évolutions">
index 15a38f0..11852d7 100644 (file)
                                     <field name="date_reel_deb" colspan="1" nolabel="1" readonly="1" />
                                     <p style="font-weight:bold" colspan="1">Date réelle fin</p>
                                     <field name="date_reel_fin" colspan="3" nolabel="1" readonly="1" />
+                                    <label for="charge_init" colspan="1" />
+                                    <field name="charge_init" colspan="2" nolabel="1" />
+                                    <label for="charge_plan" colspan="1" />
+                                    <field name="charge_plan" colspan="2" nolabel="1" />
                                 </group>
                             </page>
                             <page string="Phases">
                                 <button type="action" target="new" name="%(wizard_add_phase_to_palier)d" string="Ajouter une phase" class="oe_highlight" context="{'palier_id': id}" />
                                 <field name="phases">
-                                    <tree create="false" delete="true" editable="true">
+                                    <tree>
                                         <field name="name" />
                                     </tree>
                                 </field>