Début ajout wizard MOE
authorAlicia FLOREZ <alicflorez@gmail.com>
Tue, 14 May 2013 14:09:09 +0000 (16:09 +0200)
committerAlicia FLOREZ <alicflorez@gmail.com>
Tue, 14 May 2013 14:09:09 +0000 (16:09 +0200)
views/projet.xml
views/wizards/moe.xml [new file with mode: 0644]
wizards/moe.py

index 329e692..b1c57ee 100644 (file)
@@ -23,7 +23,8 @@
                                 <field name="main_domain" nolabel="1" widget="selection" />
                             </page>
                             <page string="MO">
-                                <p>MOe</p>
+                                <p>MOE</p>
+                                <button type="action" target="new" name="cmmi.wizards.wizard_add_moe_to_project" string="Add a MOE" class="oe_highlight" context="{'project_id': id}" />
                                 <field name="structures_moe">
                                     <tree>
                                         <field name="name" />
diff --git a/views/wizards/moe.xml b/views/wizards/moe.xml
new file mode 100644 (file)
index 0000000..f4153ec
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+
+
+    <!-- View -->
+    <record model="ir.ui.view" id="wizard_add_moe_to_project_form">
+      <field name="name">wizard.project.moe.add</field>
+      <field name="model">cmmi.projet.moe.wizard</field>
+      <field name="arch" type="xml">
+        <form string="Add MOE to Project">
+          <field name="project_id" colspan="4" readonly="1" />
+          <field name="moe_id" colspan="4" />
+          <field name="main" colspan="4" />
+          <button type="object" name="action_add_moe_to_project" string="Add MOE to Project"/>
+        </form>
+      </field>
+    </record>
+
+    <!-- Actions window -->
+    <record model="ir.actions.act_window" id="wizard_add_moe_to_project">
+      <field name="name">Add MOE to Project</field>
+      <field name="res_model">cmmi.projet.moe.wizard</field>
+      <field name="view_mode">form</field>
+      <field name="target">new</field>
+    </record>
+
+
+  </data>
+</openerp>
index 02fc908..1509b1c 100644 (file)
@@ -6,14 +6,21 @@ class ProjetMoeWizard(osv.TransientModel):
 
     _name = "cmmi.projet.moe.wizard"
 
+    def default_get(self, cr, uid, fields, context=None):
+        ret = osv.TransientModel.default_get(self, cr, uid, fields, context=context)
+        project_id = context.get('project_id', False)
+        if project_id:
+            ret['project_id'] = project_id
+        return ret
+
     def _moes_selection(self, cr, uid, context=None):
         model_base = self.pool.get("cmmi.mo.moe")
-        model_proj = self.pool.get("cmmi.projet.domaine")
+        model_proj = self.pool.get("cmmi.projet.moe")
 
         if context is None or not context.has_key("project_id"):
             return []
 
-        # recherche des lien entre le projet et les domaines
+        # recherche des lien entre le projet et les moes
         links_ids = model_proj.search(
             cr,
             uid,
@@ -31,7 +38,7 @@ class ProjetMoeWizard(osv.TransientModel):
         )]))
 
         # recherche des domaines autres que ceux déjà sélectionnés
-        domaines_ids = model_base.search(
+        moe_ids = model_base.search(
             cr,
             uid,
             [('id', 'not in', excluded_ids)],
@@ -42,22 +49,66 @@ class ProjetMoeWizard(osv.TransientModel):
         print [(r["id"], r["name"]) for r in model_base.read(
             cr,
             uid,
-            domaines_ids,
+            moe_ids,
             fields=["id", "name"],
             context=context
         )]
         return [(r["id"], r["name"]) for r in model_base.read(
             cr,
             uid,
-            domaines_ids,
+            moe_ids,
             fields=["id", "name"],
             context=context
         )]
 
+
+    def action_add_domain_to_project(self, cr, uid, ids, context=None):
+        # Récupération du modèle utile pour écrire les données
+        model = self.pool.get("cmmi.projet.moe")
+
+        # Un wizard, donc un seul identifiant
+        id = ids[0]
+
+        # Récupération des informations mises dans l'assistant
+        result = self.read(cr, uid, id, context=context)
+
+        # Si on a coché principal, on vire principal des autres moes
+        if result["main"]:
+            model.write(
+                cr,
+                uid,
+                model.search(
+                    cr,
+                    uid,
+                    [('project_id', '=', result["project_id"][0])],
+                    context=context,
+                ),
+                {'main': False},
+                context=context,
+            )
+
+        # Création de la donnée à partir de la donnée du magicien
+        model.create(cr, uid, {
+            "main": result["main"],
+            "project_id": result["project_id"][0],
+            "moe_id": result["moe_id"],
+            }, context=context)
+
+
+        # Renvoi vers la vue du modèle
+        return {
+            "type": 'ir.actions.act_window',
+            "res_model": "cmmi.projet",
+            'view_type': 'form',
+            'view_mode': 'form',
+            'res_id': result["project_id"][0],
+            'context': context,
+        }
+
     _columns = {
-        "main": fields.boolean(string="Domaine principal ?"),
+        "main": fields.boolean(string="MOE principale ?"),
         "project_id": fields.many2one("cmmi.projet",
                                       string="Projet"),
-        "domaine_id": fields.selection(_domaines_selection,
-                                      string="Domaine"),
+        "moe_id": fields.selection(_moes_selection,
+                                      string="MOE"),
     }
\ No newline at end of file