Wizard pour l'ajout d'évolutions à un projet : Done.
[OpenERP/cmmi.git] / wizards / evolution.py
1 #-*- coding: utf8 -*-
2 '''
3 '''
4
5 from openerp.osv import osv, fields
6
7 class EvolutionWizard(osv.TransientModel):
8
9     _name = "cmmi.evolution.wizard"
10
11     def default_get(self, cr, uid, fields, context=None):
12         res = osv.TransientModel.default_get(self, cr, uid, fields, context=context)
13         projet_id = context.get('project_id', False)
14         if projet_id:
15             res['projet_id'] = projet_id
16         return res
17
18
19     def _palier_selection(self, cr, uid, context=None):
20         palier_model = self.pool.get("cmmi.axes.palier")
21
22         if context is None or not context.has_key("project_id"):
23             return
24
25         palier_ids = palier_model.search(
26             cr,
27             uid,
28             [('projet_id', '=', context["project_id"])],
29             context=context
30         )
31
32         print [(p["id"], p["name"]) for p in palier_model.read(
33             cr,
34             uid,
35             palier_ids,
36             fields=["id", "name"],
37             context=context
38         )]
39         return [(p["id"], p["name"]) for p in palier_model.read(
40             cr,
41             uid,
42             palier_ids,
43             fields=["id", "name"],
44             context=context
45         )]
46
47
48     def _chantier_selection(self, cr, uid, context=None):
49         chantier_model = self.pool.get("cmmi.axes.chantier")
50
51         if context is None or not context.has_key("project_id"):
52             return
53
54         chantier_ids = chantier_model.search(
55             cr,
56             uid,
57             [('projet_id', '=', context["project_id"])],
58             context=context
59         )
60
61         print [(c["id"], c["name"]) for c in chantier_model.read(
62             cr,
63             uid,
64             chantier_ids,
65             fields=["id", "name"],
66             context=context
67         )]
68         return [(c["id"], c["name"]) for c in chantier_model.read(
69             cr,
70             uid,
71             chantier_ids,
72             fields=["id", "name"],
73             context=context
74         )]
75
76
77     def action_add_evolution(self, cr, uid, ids, context=None):
78         evolution_model = self.pool.get("cmmi.evolution")
79
80         id = ids[0]
81
82         res = self.read(cr, uid, id, context=context)
83         evolution_model.create(
84             cr,
85             uid,
86             {
87                 "name": res["name"],
88                 "palier_id": res["palier_id"],
89                 "chantier_id": res["chantier_id"],
90                 "projet_id": res["projet_id"][0],
91             },
92             context=context
93         )
94
95         return {'type': 'ir.actions.act_windows_close'}
96
97
98     _columns = {
99         "name": fields.char(string="Title", size=64, required=True),
100         "projet_id": fields.many2one("cmmi.projet",
101                                      string="Projet",
102                                      required=True),
103         "palier_id": fields.selection(_palier_selection,
104                                      string="Palier",
105                                      required=True),
106         "chantier_id": fields.selection(_chantier_selection,
107                                        string="Chantier",
108                                        required=True),
109     }