Wizard pour l'ajout de phases à un palier - TERMINÉ
authorAlicia FLOREZ <alicflorez@gmail.com>
Mon, 3 Jun 2013 12:34:56 +0000 (14:34 +0200)
committerAlicia FLOREZ <alicflorez@gmail.com>
Mon, 3 Jun 2013 12:34:56 +0000 (14:34 +0200)
__init__.py
__openerp__.py
views/palier.xml
views/wizards/chantier.xml [deleted file]
wizards/chantier.py [deleted file]
wizards/domaine.py
wizards/palierPhase.py

index 00d905e..a68caea 100644 (file)
@@ -8,4 +8,5 @@ import evolution
 
 import wizards.domaine
 import wizards.moa
-import wizards.moe
\ No newline at end of file
+import wizards.moe
+import wizards.palierPhase
\ No newline at end of file
index 425c202..1cc9e4c 100644 (file)
@@ -15,6 +15,7 @@
         'views/wizards/domaine.xml',
         'views/wizards/moe.xml',
         'views/wizards/moa.xml',
+        'views/wizards/palierPhase.xml',
         # Vues associées aux modèles
         'views/phase.xml',
 #        'views/team_member.xml',
index 989108f..4e343e2 100644 (file)
@@ -47,6 +47,7 @@
                                 </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">
                                         <field name="name" />
diff --git a/views/wizards/chantier.xml b/views/wizards/chantier.xml
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/wizards/chantier.py b/wizards/chantier.py
deleted file mode 100644 (file)
index 006d389..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#-*- coding: utf8 -*-
-
-from openerp.osv import osv, fields
-
-class ProjetChantierWizard(osv.TransientModel):
-
-    _name = "cmmi.projet.chantier.wizard"
\ No newline at end of file
index 510150c..ec4093e 100644 (file)
@@ -7,7 +7,7 @@ from openerp.osv import osv, fields
 
 #TODO: Il faut que si l'on coche une autre case, le rafraichissement se fasse.
 
-#FIXME: erreur inexpliquée à corriger.
+#TODO: erreur inexpliquée à corriger.
 
 class ProjetDomaineWizard(osv.TransientModel):
 
index 8716880..26375df 100644 (file)
@@ -2,7 +2,6 @@
 
 from openerp.osv import osv, fields
 
-# TODO: finir PalierPhaseWizard
 class PalierPhaseWizard(osv.TransientModel):
 
     _name = "cmmi.palier.phase.wizard"
@@ -16,14 +15,69 @@ class PalierPhaseWizard(osv.TransientModel):
         return result
 
 
-
     def _phases_selection(self, cr, uid, context=None):
-        phase_model = self.pool.get("cmmi.phase")
+        phase_model = self.pool.get("cmmi.projet.phase")
         palier_phase_model = self.pool.get("cmmi.axes.palier.phase")
 
         if context is None or not context.has_key("palier_id"):
             return []
 
+        # on recherche des palier-phases
+        links_ids = palier_phase_model.search(
+            cr,
+            uid,
+            [('palier_id', '=', context["palier_id"])],
+            context=context,
+        )
+
+        # on recherche phases déjà présentes dans le palier
+        excluded_ids = list(set([p['phase_id'][0] for p in palier_phase_model.read(
+            cr,
+            uid,
+            links_ids,
+            fields=["phase_id"],
+            context=context
+        )]))
+
+        # on exclu les phases déjà présentes dans le palier
+        phases_ids = phase_model.search(
+            cr,
+            uid,
+            [('id', 'not in', excluded_ids), ('selectionne', '=', True)],
+            context=context,
+        )
+
+        print [(p["id"], p["name"]) for p in phase_model.read(
+            cr,
+            uid,
+            phases_ids,
+            fields=["id", "name"],
+            context=context
+        )]
+        return [(p["id"], p["name"]) for p in phase_model.read(
+            cr,
+            uid,
+            phases_ids,
+            fields=["id", "name"],
+            context=context
+        )]
+
+
+    def action_add_phase_to_palier(self, cr, uid, ids, context=None):
+        palier_phase_model = self.pool.get("cmmi.axes.palier.phase")
+
+        id = ids[0]
+
+        result = self.read(cr, uid, id, context=context)
+
+        palier_phase_model.create (
+            cr,
+            uid,
+            {"palier_id": result["palier_id"][0],"phase_id": result["phase_id"]},
+            context=context,
+        )
+
+        return {'type': 'ir.actions.act_window_close'}
 
 
     _columns = {
@@ -34,7 +88,7 @@ class PalierPhaseWizard(osv.TransientModel):
 #                                     string="Phase",
 #                                     required=True,
 #                                     domain=[("selectionne", "=", True)]),
-        "phase_id": fields.function(_phases_selection,
+        "phase_id": fields.selection(_phases_selection,
                                     string="Phase",
                                     required=True),
     }
\ No newline at end of file