Merge branch 'master' of ssh://inspyration.org/~/OpenERP/cmmi
[OpenERP/cmmi.git] / projet.py
index 7defaf7..454682b 100644 (file)
--- a/projet.py
+++ b/projet.py
@@ -42,7 +42,7 @@ class Projet(osv.Model):
         "paliers": fields.one2many("cmmi.axes.palier",
                                    "projet_id",
                                    string="Paliers"),
-        "phases": fields.one2many("cmmi.phase",
+        "phases": fields.one2many("cmmi.projet.phase",
                                   "projet_id",
                                   string="Phases"),
         "evolutions": fields.one2many("cmmi.evolution",
@@ -56,6 +56,14 @@ class Projet(osv.Model):
                                           string="Structure principale"),
     }
 
+    def action_add_domain(self, cr, uid, ids, context=None):
+        pass
+
+    def action_add_moe(self, cr, uid, ids, context=None):
+        pass
+
+    def action_add_moa(self, cr, uid, ids, context=None):
+        pass
 
 class ProjetDomaine(osv.Model):
 
@@ -69,9 +77,6 @@ class ProjetDomaine(osv.Model):
         return dict([(i, r.domaine_id.name) for i, r in
                 zip(ids, self.browse(cr, uid, ids, context=context))])
 
-    def _set_name(self, cr, uid, _id, name, value, arg=None, context=None):
-        self.write(cr, uid, _id, {name: value}, context)
-
     _columns = {
         "name": fields.function(_get_name,
                                 type='char',
@@ -83,3 +88,101 @@ class ProjetDomaine(osv.Model):
         "domaine_id": fields.many2one("cmmi.description.domaine",
                                       string="Domaine"),
     }
+
+    def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
+        if not main:
+            return {'value': {'main': True},
+                    'warning': {
+                        'title'   : "Integrity Warning",
+                        'message' : "One of the domains should be the main domain",
+                    }
+                }
+        ids = self.search(
+            cr,
+            uid,
+            [
+                ('project_id', '=', project),
+                ('domaine_id', '!=', domaine),
+            ],
+            context=context,
+        )
+        current_id = self.search(
+            cr,
+            uid,
+            [
+                ('project_id', '=', project),
+                ('domaine_id', '=', domaine),
+            ],
+            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 ProjetMoe(osv.Model):
+    _name = "cmmi.projet.moe"
+
+    def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if isinstance(ids, (int, long)):
+            ids = [ids]
+        return dict([(i, r.moe_id.name) for i, r in
+                zip(ids, self.browse(cr, uid, ids, context=context))])
+
+    _columns = {
+        "name": fields.function(_get_name,
+                                type='char',
+                                store=True, # Permet d'enregistrer le champ.
+                                string="Nom de la MOE"),
+        "main": fields.boolean(string="MOE principale ?"),
+        "project_id": fields.many2one("cmmi.projet",
+                                      string="Projet"),
+        "moe_id": fields.many2one("cmmi.mo.moe",
+                                      string="MOE"),
+    }
+
+
+class ProjetMoa(osv.Model):
+    _name = "cmmi.projet.moe"
+
+    def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if isinstance(ids, (int, long)):
+            ids = [ids]
+        return dict([(i, r.moa_id.name) for i, r in
+                zip(ids, self.browse(cr, uid, ids, context=context))])
+
+    _columns = {
+        "name": fields.function(_get_name,
+                                type='char',
+                                store=True,
+                                string="Nom de la MOA"),
+        "main": fields.boolean(string="MOA principale ?"),
+        "project_id": fields.many2one("cmmi.projet",
+                                      string="Projet"),
+        "moa_id": fields.many2one("cmmi.mo.moa",
+                                      string="MOA"),
+    }
+
+
+class ProjetPhase(osv.Model):
+    _name = "cmmi.projet.phase"
+
+    def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if isinstance(ids, (int, long)):
+            ids = [ids]
+        return dict([(i, r.phase_id.name) for i, r in
+                zip(ids, self.browse(cr, uid, ids, context=context))])
+
+    _columns = {
+        "name": fields.function(_get_name,
+                                type='char',
+                                store=True,
+                                string="Nom de la phase"),
+        "selectionne": fields.boolean(string="Phase sélectionnée ?"),
+        "projet_id": fields.many2one("cmmi.projet",
+                                     string="Projet"),
+        "phase_id": fields.many2one("cmmi.phase",
+                                    string="Phase"),
+    }
\ No newline at end of file