454682b8c787bbc117f1c828efaaf93c5c78e31a
[OpenERP/cmmi.git] / projet.py
1 #-*- coding: utf8 -*-
2 '''
3 '''
4
5 from openerp.osv import osv, fields
6
7
8 class Projet(osv.Model):
9
10     _name = "cmmi.projet"
11
12     _domains = {
13         'moe': [('role_mo_id.type_mo', '=', "MOE")],
14         'moa': [('role_mo_id.type_mo', '=', "MOA")],
15     }
16
17     _columns = {
18         "name": fields.char(string="Title", size=64, required=True),
19         "description": fields.text(string="Description"),
20         "domaines": fields.one2many("cmmi.projet.domaine",
21                                     "project_id",
22                                     string="Domaines"),
23         "structures": fields.many2many("cmmi.mo.structure",
24                                        string="Structures"),
25         "structures_moe": fields.many2many("cmmi.mo.structure",
26                                            string="Structures",
27                                            domain=_domains['moe']),
28         "structures_moa": fields.many2many("cmmi.mo.structure",
29                                            string="Structures",
30                                            domain=_domains['moa']),
31         "team_members": fields.many2many("cmmi.partner.teammember",
32                                          "cmmi_projet_teammember_rel",
33                                          "projet_id",
34                                          "partner_id",
35                                          string="Team Members"),
36         "modules": fields.one2many("cmmi.description.module",
37                                    "projet_id",
38                                    string="Modules"),
39         "chantiers": fields.one2many("cmmi.axes.chantier",
40                                      "projet_id",
41                                      string="Chantiers"),
42         "paliers": fields.one2many("cmmi.axes.palier",
43                                    "projet_id",
44                                    string="Paliers"),
45         "phases": fields.one2many("cmmi.projet.phase",
46                                   "projet_id",
47                                   string="Phases"),
48         "evolutions": fields.one2many("cmmi.evolution",
49                                       "projet_id",
50                                       string="Evolutions"),
51         "moe_id": fields.many2one("cmmi.mo.moe", string="MoE", required=True),
52         "moa_id": fields.many2one("cmmi.mo.moa", string="MoA", required=True),
53         "main_domain": fields.many2one("cmmi.description.domaine",
54                                        string="Domaine principal"),
55         "main_structure": fields.many2one("cmmi.mo.structure",
56                                           string="Structure principale"),
57     }
58
59     def action_add_domain(self, cr, uid, ids, context=None):
60         pass
61
62     def action_add_moe(self, cr, uid, ids, context=None):
63         pass
64
65     def action_add_moa(self, cr, uid, ids, context=None):
66         pass
67
68 class ProjetDomaine(osv.Model):
69
70     _name = "cmmi.projet.domaine"
71
72     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
73         if isinstance(ids, (int, long)):
74             ids = [ids]
75         #return {i: r.domaine_id.name for i, r in
76         #        zip(ids, self.browse(cr, uid, ids, context=context))}
77         return dict([(i, r.domaine_id.name) for i, r in
78                 zip(ids, self.browse(cr, uid, ids, context=context))])
79
80     _columns = {
81         "name": fields.function(_get_name,
82                                 type='char',
83                                 store=True,
84                                 string="Nom du domaine"),
85         "main": fields.boolean(string="Domaine principal ?"),
86         "project_id": fields.many2one("cmmi.projet",
87                                       string="Projet"),
88         "domaine_id": fields.many2one("cmmi.description.domaine",
89                                       string="Domaine"),
90     }
91
92     def onchange_main(self, cr, uid, ids, project, domaine, main, context=None):
93         if not main:
94             return {'value': {'main': True},
95                     'warning': {
96                         'title'   : "Integrity Warning",
97                         'message' : "One of the domains should be the main domain",
98                     }
99                 }
100         ids = self.search(
101             cr,
102             uid,
103             [
104                 ('project_id', '=', project),
105                 ('domaine_id', '!=', domaine),
106             ],
107             context=context,
108         )
109         current_id = self.search(
110             cr,
111             uid,
112             [
113                 ('project_id', '=', project),
114                 ('domaine_id', '=', domaine),
115             ],
116             context=context,
117         )
118         self.write(cr, uid, ids, {'main': False}, context=context)
119         self.write(cr, uid, current_id, {'main': True}, context=context)
120
121         return {'value': {'main': True}}
122
123
124
125 class ProjetMoe(osv.Model):
126     _name = "cmmi.projet.moe"
127
128     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
129         if isinstance(ids, (int, long)):
130             ids = [ids]
131         return dict([(i, r.moe_id.name) for i, r in
132                 zip(ids, self.browse(cr, uid, ids, context=context))])
133
134     _columns = {
135         "name": fields.function(_get_name,
136                                 type='char',
137                                 store=True, # Permet d'enregistrer le champ.
138                                 string="Nom de la MOE"),
139         "main": fields.boolean(string="MOE principale ?"),
140         "project_id": fields.many2one("cmmi.projet",
141                                       string="Projet"),
142         "moe_id": fields.many2one("cmmi.mo.moe",
143                                       string="MOE"),
144     }
145
146
147 class ProjetMoa(osv.Model):
148     _name = "cmmi.projet.moe"
149
150     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
151         if isinstance(ids, (int, long)):
152             ids = [ids]
153         return dict([(i, r.moa_id.name) for i, r in
154                 zip(ids, self.browse(cr, uid, ids, context=context))])
155
156     _columns = {
157         "name": fields.function(_get_name,
158                                 type='char',
159                                 store=True,
160                                 string="Nom de la MOA"),
161         "main": fields.boolean(string="MOA principale ?"),
162         "project_id": fields.many2one("cmmi.projet",
163                                       string="Projet"),
164         "moa_id": fields.many2one("cmmi.mo.moa",
165                                       string="MOA"),
166     }
167
168
169 class ProjetPhase(osv.Model):
170     _name = "cmmi.projet.phase"
171
172     def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None):
173         if isinstance(ids, (int, long)):
174             ids = [ids]
175         return dict([(i, r.phase_id.name) for i, r in
176                 zip(ids, self.browse(cr, uid, ids, context=context))])
177
178     _columns = {
179         "name": fields.function(_get_name,
180                                 type='char',
181                                 store=True,
182                                 string="Nom de la phase"),
183         "selectionne": fields.boolean(string="Phase sélectionnée ?"),
184         "projet_id": fields.many2one("cmmi.projet",
185                                      string="Projet"),
186         "phase_id": fields.many2one("cmmi.phase",
187                                     string="Phase"),
188     }