Ajout d'un wizard pour l'ajout des MOA à un projet
authorAlicia FLOREZ <alicflorez@gmail.com>
Thu, 23 May 2013 08:26:43 +0000 (10:26 +0200)
committerAlicia FLOREZ <alicflorez@gmail.com>
Thu, 23 May 2013 08:26:43 +0000 (10:26 +0200)
__openerp__.py
views/projet.xml
views/wizards/moa.xml [new file with mode: 0644]
wizards/moa.py [new file with mode: 0644]

index 558e38e..2b44c3d 100644 (file)
@@ -8,6 +8,8 @@
     "data": [
         # Vues associées aux assistants
         'views/wizards/domaine.xml',
+        #'views/wizards/moe.xml',
+        #'views/wizards/moa.xml',
         # Vues associées aux modèles
         'views/projet.xml',
         'views/evolution.xml',
index b1c57ee..13f3fe6 100644 (file)
@@ -23,8 +23,8 @@
                                 <field name="main_domain" nolabel="1" widget="selection" />
                             </page>
                             <page string="MO">
-                                <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}" />
+                                <p>MOE</p><!--
+                                <button type="object" target="new" name="cmmi.wizard_add_moe_to_project" string="Add a MOE" class="oe_highlight" context="{'project_id': id}" />-->
                                 <field name="structures_moe">
                                     <tree>
                                         <field name="name" />
@@ -32,7 +32,8 @@
                                         <field name="role_mo_id" />
                                     </tree>
                                 </field>
-                                <p>MOa</p>
+                                <p>MOa</p><!--
+                                <button type="object" target="new" name="cmmi.wizard_add_moa_to_project" string="Add a MOA" class="oe_highlight" context="{'project_id': id}" />-->
                                 <field name="structures_moe">
                                     <tree>
                                         <field name="name" />
diff --git a/views/wizards/moa.xml b/views/wizards/moa.xml
new file mode 100644 (file)
index 0000000..0379e7b
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+
+
+    <!-- View -->
+    <record model="ir.ui.view" id="wizard_add_moa_to_project_form">
+      <field name="name">wizard.project.moa.add</field>
+      <field name="model">cmmi.projet.moa.wizard</field>
+      <field name="arch" type="xml">
+        <form string="Add MOA to Project">
+          <field name="project_id" colspan="4" readonly="1" />
+          <field name="moa_id" colspan="4" />
+          <field name="main" colspan="4" />
+          <button type="object" name="action_add_moa_to_project" string="Add MOA to Project"/>
+        </form>
+      </field>
+    </record>
+
+    <!-- Actions window -->
+    <record model="ir.actions.act_window" id="wizard_add_moa_to_project">
+      <field name="name">Add MOA to Project</field>
+      <field name="res_model">cmmi.projet.moa.wizard</field>
+      <field name="view_mode">form</field>
+      <field name="target">new</field>
+    </record>
+
+
+  </data>
+</openerp>
diff --git a/wizards/moa.py b/wizards/moa.py
new file mode 100644 (file)
index 0000000..68b8ce3
--- /dev/null
@@ -0,0 +1,114 @@
+#-*- coding: utf8 -*-
+
+from openerp.osv import osv, fields
+
+class ProjetMoaWizard(osv.TransientModel):
+
+    _name = "cmmi.projet.moa.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 _moas_selection(self, cr, uid, context=None):
+        model_base = self.pool.get("cmmi.mo.moa")
+        model_proj = self.pool.get("cmmi.projet.moa")
+
+        if context is None or not context.has_key("project_id"):
+            return []
+
+        # recherche des lien entre le projet et les moas
+        links_ids = model_proj.search(
+            cr,
+            uid,
+            [('project_id', '=', context["project_id"])],
+            context=context,
+        )
+
+        # récupérations des moas déjà sélectionnés pour le projet
+        excluded_ids = list(set([r['moa_id'][0] for r in model_proj.read(
+            cr,
+            uid,
+            links_ids,
+            fields=["moa_id"],
+            context=context
+        )]))
+
+        # recherche des domaines autres que ceux déjà sélectionnés
+        moa_ids = model_base.search(
+            cr,
+            uid,
+            [('id', 'not in', excluded_ids)],
+            context=context,
+        )
+
+        # renvoi des 2 uplets (id, name)
+        print [(r["id"], r["name"]) for r in model_base.read(
+            cr,
+            uid,
+            moa_ids,
+            fields=["id", "name"],
+            context=context
+        )]
+        return [(r["id"], r["name"]) for r in model_base.read(
+            cr,
+            uid,
+            moa_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.moa")
+
+        # 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 moas
+        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],
+            "moa_id": result["moa_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="MOA principale ?"),
+        "project_id": fields.many2one("cmmi.projet",
+                                      string="Projet"),
+        "moa_id": fields.selection(_moas_selection,
+                                      string="moa"),
+    }
\ No newline at end of file