Ajout d'un champ charge_reel dans palier
[OpenERP/cmmi.git] / projet.py
index 9381694..f37b957 100644 (file)
--- a/projet.py
+++ b/projet.py
@@ -5,10 +5,13 @@
 from openerp.osv import osv, fields
 
 
+# ================================== PROJET ================================= #
 class Projet(osv.Model):
 
     _name = "cmmi.projet"
 
+    _description = "Table des projets."
+
     def _get_main_domain(self, cr, uid, ids, field_name=None, arg=None, context=None):
         if type(ids) in (int, float):
             ids = [ids]
@@ -62,20 +65,39 @@ class Projet(osv.Model):
                     break
             else:
                 result[project.id] = "Any MOE is selected as main MOE yet"
+        return result
 
+
+    def _get_phases_selectionnees(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        result = {}
+        for projet in self.browse(cr, uid, ids, context=context):
+            res = []
+            for phase in projet.phases:
+                #import pdb; pdb.set_trace()
+                if phase.selectionne:
+                    res.append(phase.id)
+            result[projet.id] = res
         return result
 
 
     _columns = {
         "name": fields.char(string="Title", size=64, required=True),
         "description": fields.text(string="Description"),
+        "use_chantier": fields.boolean(string="Utilisation de la notion de chantier ?"),
+        "use_palier": fields.boolean(string="Utilisation de la notion de palier ?"),
+
+        # Backrefs
         "domains": fields.one2many("cmmi.projet.domaine",
                                     "project_id",
                                     string="Domaines"),
-        "team_members": fields.many2many("res.partner",
-                                         "cmmi_projet_teammember_rel",
+        "moe_ids": fields.one2many("cmmi.projet.moe",
+                                   "project_id",
+                                   string="MOEs"),
+        "moa_ids": fields.one2many("cmmi.projet.moa",
+                                   "project_id",
+                                   string="MOAs"),
+        "team_members": fields.one2many("cmmi.projet.teammember",
                                          "projet_id",
-                                         "partner_id",
                                          string="Team Members"),
         "modules": fields.one2many("cmmi.description.module",
                                    "projet_id",
@@ -92,12 +114,8 @@ class Projet(osv.Model):
         "evolutions": fields.one2many("cmmi.evolution",
                                       "projet_id",
                                       string="Evolutions"),
-        "moe_ids": fields.one2many("cmmi.projet.moe",
-                                   "project_id",
-                                   string="MOEs"),
-        "moa_ids": fields.one2many("cmmi.projet.moa",
-                                   "project_id",
-                                   string="MOAs"),
+
+        # Champs fonction rapatriant les mo ou domaine principaux
         "moe_id": fields.function(_get_main_moe,
                                   type="string",
                                   string="MOE principale"),
@@ -107,6 +125,15 @@ class Projet(osv.Model):
         "main_domain": fields.function(_get_main_domain,
                                        type="string",
                                        string="Domaine principal"),
+        "phases_selectionnees": fields.function(_get_phases_selectionnees,
+                                                type="one2many",
+                                                obj="cmmi.projet.phase",
+                                                string="Phases sélectionnées"),
+    }
+
+    _defaults = {
+        "use_chantier": True,
+        "use_palier": True,
     }
 
 
@@ -114,7 +141,7 @@ class Projet(osv.Model):
         project_id = osv.Model.create(self, cr, uid, vals, context=context)
 
         # Récupération des ids de toutes les phases
-        phase_model = self.pool.get("cmmi.phase.type")
+        phase_model = self.pool.get("cmmi.phase")
         phases_ids = phase_model.search(cr, uid, [])
 
         # Création des relations
@@ -142,10 +169,15 @@ class Projet(osv.Model):
     def action_add_moa(self, cr, uid, ids, context=None):
         pass
 
+
+
+# ============================= PROJET DOMAINE ============================== #
 class ProjetDomaine(osv.Model):
 
     _name = "cmmi.projet.domaine"
 
+    _description = "Rattachement des domaines a un projet."
+
     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
         if isinstance(ids, (int, long)):
             ids = [ids]
@@ -199,9 +231,12 @@ class ProjetDomaine(osv.Model):
 
 
 
+# =============================== PROJET MOE ================================ #
 class ProjetMoe(osv.Model):
     _name = "cmmi.projet.moe"
 
+    _description = "Rattachement des MOEs au projet."
+
     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
         if isinstance(ids, (int, long)):
             ids = [ids]
@@ -254,9 +289,13 @@ class ProjetMoe(osv.Model):
         return {'value': {'main': True}}
 
 
+
+# =============================== PROJET MOA ================================ #
 class ProjetMoa(osv.Model):
     _name = "cmmi.projet.moa"
 
+    _description = "Rattachement des MOAs a une projet."
+
     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
         if isinstance(ids, (int, long)):
             ids = [ids]
@@ -309,25 +348,65 @@ class ProjetMoa(osv.Model):
         return {'value': {'main': True}}
 
 
+
+# =============================== PROJET PHASE ============================== #
 class ProjetPhase(osv.Model):
     _name = "cmmi.projet.phase"
 
-    def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+    _description = "Rattachement des Phases aux projets"
+
+    _columns = {
+        "name": fields.related("phase_id",
+                                "name",
+                                read_only=True,
+                                type="char",
+                                relation="cmmi.phase",
+                                string="Nom de la phase"),
+        "phase_id": fields.many2one("cmmi.phase",
+                                    string="Phase",
+                                    required=True),
+        "projet_id": fields.many2one("cmmi.projet",
+                                     string="Projet",
+                                     required=True),
+        "selectionne": fields.boolean(string="Phase sélectionnée ?"),
+    }
+
+
+
+# ============================ PROJET TEAM MEMBER =========================== #
+class ProjetTeammember(osv.Model):
+    _name = "cmmi.projet.teammember"
+
+    _description = "Rattachement des Team members a un projet."
+
+    def _get_partner_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
+        return dict([(i, r.partner_id.name) for i, r in
+                zip(ids, self.browse(cr, uid, ids, context=context))])
+
+    def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
+        if isinstance(ids, (int, long)):
+            ids = [ids]
+        return dict([(i, r.projet_id.name) for i, r in
                 zip(ids, self.browse(cr, uid, ids, context=context))])
 
     _columns = {
-        "name": fields.function(_get_name,
+        "name": fields.function(_get_partner_name,
                                 type='char',
                                 store=True,
-                                string="Nom de la phase"),
-        "selectionne": fields.boolean(string="Phase sélectionnée ?"),
+                                string="Nom du partner"),
+        "projet_name": fields.function(_get_project_name,
+                                       type='char',
+                                       store=True,
+                                       string="Nom du projet"),
+        "affecte": fields.integer(string="Affecté à"),
+        "depuis": fields.date(string="Depuis"),
+        "jusqua": fields.date(string="Jusqu'à"),
         "projet_id": fields.many2one("cmmi.projet",
                                      string="Projet",
                                      required=True),
-        "phase_id": fields.many2one("cmmi.phase.type",
-                                    string="Phase",
+        "partner_id": fields.many2one("res.partner",
+                                    string="Team Member",
                                     required=True),
-    }
\ No newline at end of file
+    }