Ajout de boutons permettant le contrôle de l'état d'une évolution
authorAlicia FLOREZ <alicflorez@gmail.com>
Wed, 12 Jun 2013 15:29:57 +0000 (17:29 +0200)
committerAlicia FLOREZ <alicflorez@gmail.com>
Wed, 12 Jun 2013 15:29:57 +0000 (17:29 +0200)
evolution.py
views/evolution.xml
views/projet.xml
wizards/evolution.py

index 3c68f5c..4921278 100644 (file)
@@ -31,7 +31,7 @@ class Evolution(osv.Model):
         "commentaire": fields.text(string="Commentaire"),
         "keywords": fields.text(string="Mots clés"),
         "priorite": fields.selection(_priorites, string="Priorité"),
-        "statut": fields.selection(_statuts, string="Statut"),
+        "state": fields.selection(_statuts, string="Statut"),
 #        "charges": fields.one2many("cmmi.evolution.charge", # Supprimé !
 #                                   "evolution_id",
 #                                   string="Charges"),
@@ -49,8 +49,105 @@ class Evolution(osv.Model):
                                      domain=_domains['human']),
     }
 
+    _defaults = {
+        "state": "cree",
+    }
 
-# ================================== PHASE ================================== #
+    def action_commencer(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        evo = self.read(cr, uid, ids, ['state'], context)
+
+        if evo['state'] != 'cree':
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'encours'},
+            context,
+        )
+        return self
+
+    def action_suspendre(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        evo = self.read(cr, uid, ids, ['state'], context)
+        if evo['state'] != 'encours':
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'suspendu'},
+            context,
+        )
+        return self
+
+    def action_terminer(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        evo = self.read(cr, uid, ids, ['state'], context)
+        if evo['state'] != 'encours':
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'termine'},
+            context,
+        )
+        return self
+
+    def action_abandonner(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        evo = self.read(cr, uid, ids, ['state'], context)
+
+        if not ('encours', 'cree').__contains__(evo['state']):
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'abandonne'},
+            context,
+        )
+        return self
+
+    def action_reprendre(self, cr, uid, ids, context=None):
+        if type(ids) == list:
+            if len(ids) != 1:
+                return # TODO: message d'avertissement
+            ids = ids[0]
+
+        evo = self.read(cr, uid, ids, ['state'], context)
+
+        if evo['state'] != 'suspendu':
+            return
+        self.write(
+            cr,
+            uid,
+            ids,
+            {'state': 'encours'},
+            context,
+        )
+        return self
+
+
+# =========================== EVOLUTION PHASE =============================== #
 class Phase(osv.Model):
     _name = "cmmi.evolution.phase"
 
@@ -100,7 +197,7 @@ class Phase(osv.Model):
         return osv.Model.create(self, cr, uid, vals, context=context)
 
 
-# ================================== CHARGE ================================= #
+# =========================== EVOLUTION CHARGE ============================== #
 class Charge(osv.Model):
     _name = "cmmi.evolution.charge"
 
index e9c032e..0e5f8c5 100644 (file)
@@ -8,14 +8,20 @@
             <field name="model">cmmi.evolution</field>
             <field name="arch" type="xml">
                 <form string="Formulaire évolution" version="7.0">
-                    <header />
+                    <header>
+                        <button string="Commencer" type="object" name="action_commencer" states="cree" class="oe_highlight" />
+                        <button string="Suspendre" type="object" name="action_suspendre" states="encours" class="oe_highlight" />
+                        <button string="Terminer" type="object" name="action_terminer" states="encours" class="oe_highlight" />
+                        <button string="Abandonner" type="object" name="action_abandonner" states="encours,cree" class="oe_highlight" />
+                        <button string="Reprendre" type="object" name="action_reprendre" states="suspendu" class="oe_highlight" />
+                    </header>
 
                     <sheet>
                         <group colspan="4" col="3">
                             <field name="name" colspan="3"/>
                             <field name="pid" colspan="3"/>
                             <field name="priorite" colspan="3"/>
-                            <field name="statut" colspan="3"/>
+                            <field name="state" colspan="3"/>
                         </group>
                         <notebook colspan="4">
                             <page string="Détails">
index 4040ff7..1b23a0c 100644 (file)
                                         <field name="priorite" />
                                         <field name="palier_id" />
                                         <field name="chantier_id" />
-                                        <field name="statut" />
+                                        <field name="state" />
                                     </tree>
                                 </field>
                             </page>
index b901461..52b6414 100644 (file)
@@ -88,6 +88,7 @@ class EvolutionWizard(osv.TransientModel):
                 "description": res["description"],
                 "objectif": res["objectif"],
                 "commentaire": res["commentaire"],
+                "keywords": res["keywords"],
                 "palier_id": res["palier_id"],
                 "chantier_id": res["chantier_id"],
                 "projet_id": res["projet_id"][0],