Prise en compte de la MOA principale pour les projets
authorAlicia FLOREZ <alicflorez@gmail.com>
Fri, 24 May 2013 14:34:53 +0000 (16:34 +0200)
committerAlicia FLOREZ <alicflorez@gmail.com>
Fri, 24 May 2013 14:34:53 +0000 (16:34 +0200)
demo/projet.xml
projet.py
views/projet.xml

index b9d1752..79c8f85 100644 (file)
         </record>
 
 
+        <record id="cmmi_moa_1" model="cmmi.mo.moa">
+            <field name="name">Parleurs</field>
+            <field name="description">Gens qui veulent parler</field>
+            <field name="rang">primaire</field>
+            <field name="role_mo_id" ref="cmmi_moa_3" />
+        </record>
+
+
+        <record id="cmmi_moa_2" model="cmmi.mo.moa">
+            <field name="name">Blablateurs</field>
+            <field name="description">Gens qui aiment parler</field>
+            <field name="rang">primaire</field>
+            <field name="role_mo_id" ref="cmmi_moa_3" />
+        </record>
+
+
         <record id="projet_projet_1" model="cmmi.projet">
             <field name="name">Projet of the doom</field>
             <field name="description">Ici c'est la description de ce super projet !</field><!--
index d312223..153a64d 100644 (file)
--- a/projet.py
+++ b/projet.py
@@ -28,6 +28,25 @@ class Projet(osv.Model):
         return result
 
 
+    def _get_main_moa(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if type(ids) in (int, float):
+            ids = [ids]
+
+        projects = self.browse(cr, uid, ids, context=context)
+
+        result = {}
+
+        for project in projects:
+            for moa in project.moa_ids:
+                if moa.main:
+                    result[project.id] = moa.name
+                    break
+            else:
+                result[project.id] = "Any moa is selected as main moa yet"
+
+        return result
+
+
     _columns = {
         "name": fields.char(string="Title", size=64, required=True),
         "description": fields.text(string="Description"),
@@ -64,15 +83,15 @@ class Projet(osv.Model):
                                   "project_id",
                                   string="MOE principale",
                                   domaine=[('main', '=', True)]),
-        "moa_id": fields.one2many("cmmi.projet.moa",
-                                  "project_id",
-                                  string="MOA principale",
-                                  domaine=[('main', '=', True)]),
+        "moa_id": fields.function(_get_main_moa,
+                                  type="string",
+                                  string="MOA principale"),
         "main_domain": fields.function(_get_main_domain,
                                        type="string",
                                        string="Domaine principal"),
     }
 
+
     def create(self, cr, uid, vals, context=None):
         project_id = osv.Model.create(self, cr, uid, vals, context=context)
 
@@ -213,7 +232,35 @@ class ProjetMoa(osv.Model):
     }
 
     def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
-        pass
+        if not main:
+            return {'value': {'main': True},
+                    'warning': {
+                        'title'   : "Integrity Warning",
+                        'message' : "Une des MOA doit ĂȘtre la MOA principale",
+                    }
+                }
+        ids = self.search(
+            cr,
+            uid,
+            [
+                ('project_id', '=', project),
+                ('moa_id', '!=', moa),
+            ],
+            context=context,
+        )
+        current_id = self.search(
+            cr,
+            uid,
+            [
+                ('project_id', '=', project),
+                ('moa_id', '=', moa),
+            ],
+            context=context,
+        )
+        self.write(cr, uid, ids, {'main': False}, context=context)
+        self.write(cr, uid, current_id, {'main': True}, context=context)
+
+        return {'value': {'main': True}}
 
 
 class ProjetPhase(osv.Model):
index c5ced1a..da6de3e 100644 (file)
                         <field name="name" nolabel="1" />
                         <notebook colspan="4">
                             <page string="Projet">
-                                <field name="description" nolabel="1" /><!--
-                                <label for="moe_id" colspan="1" />
+                                <field name="description" nolabel="1" />
+                                <label for="moe_id" />
                                 <field name="moe_id" nolabel="1" />
-                                <label for="moa_id" colspan="1" />
-                                <field name="moa_id" nolabel="1" />-->
-                                <label for="main_domain" colspan="1" />
+                                <label for="moa_id" />
+                                <field name="moa_id" nolabel="1" widget="text" />
+                                <label for="main_domain" />
                                 <field name="main_domain" nolabel="1" widget="text" />
                             </page>
                             <page string="MO">