Gestion du domaine principal
authorSébastien CHAZALLET <s.chazallet@gmail.com>
Thu, 23 May 2013 14:49:27 +0000 (16:49 +0200)
committerSébastien CHAZALLET <s.chazallet@gmail.com>
Thu, 23 May 2013 14:49:27 +0000 (16:49 +0200)
projet.py
views/projet.xml

index 4e2e7a6..8967371 100644 (file)
--- a/projet.py
+++ b/projet.py
@@ -9,10 +9,29 @@ class Projet(osv.Model):
 
     _name = "cmmi.projet"
 
+    def _get_main_domain(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 domain in project.domains:
+                if domain.main:
+                    result[project.id] = domain.name
+                    break
+            else:
+                result[project.id] = "Any domain is selected as main domain yet"
+
+        return result
+
+
     _columns = {
         "name": fields.char(string="Title", size=64, required=True),
         "description": fields.text(string="Description"),
-        "domaines": fields.one2many("cmmi.projet.domaine",
+        "domains": fields.one2many("cmmi.projet.domaine",
                                     "project_id",
                                     string="Domaines"),
         "team_members": fields.many2many("cmmi.partner.teammember",
@@ -49,10 +68,9 @@ class Projet(osv.Model):
                                   "project_id",
                                   string="MOA principale",
                                   domaine=[('main', '=', True)]),
-        "main_domain": fields.one2many("cmmi.projet.domaine",
-                                       "project_id",
-                                       string="Domaine principal",
-                                       domaine=[('main', '=', True)]),
+        "main_domain": fields.function(_get_main_domain,
+                                       type="string",
+                                       string="Domaine principal"),
     }
 
     def action_add_domain(self, cr, uid, ids, context=None):
index 3d150aa..bd1199a 100644 (file)
@@ -18,9 +18,9 @@
                                 <label for="moe_id" colspan="1" />
                                 <field name="moe_id" nolabel="1" />
                                 <label for="moa_id" colspan="1" />
-                                <field name="moa_id" nolabel="1" />
+                                <field name="moa_id" nolabel="1" />-->
                                 <label for="main_domain" colspan="1" />
-                                <field name="main_domain" nolabel="1" widget="selection" />-->
+                                <field name="main_domain" nolabel="1" widget="text" />
                             </page>
                             <page string="MO">
                                 <p>MOE</p>
@@ -56,7 +56,7 @@
                             </page>
                             <page string="Domaines">
                                 <button type="action" target="new" name="cmmi.wizard_add_domain_to_project" string="Add a domain" class="oe_highlight" context="{'project_id': id}" />
-                                <field name="domaines">
+                                <field name="domains">
                                     <tree create="false" delete="true" editable="true">
                                         <field name="project_id" invisible="1" />
                                         <field name="domaine_id" invisible="1" />