Modification vue wizard
[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                 "description": res["description"],
89                 "objectif": res["objectif"],
90                 "commentaire": res["commentaire"],
91                 "palier_id": res["palier_id"],
92                 "chantier_id": res["chantier_id"],
93                 "projet_id": res["projet_id"][0],
94             },
95             context=context
96         )
97
98         return {'type': 'ir.actions.act_windows_close'}
99
100
101     _columns = {
102         "pid": fields.integer(string="PID"),
103         "name": fields.char(string="Title", size=64, required=True),
104         "description": fields.text(string="Description"),
105         "objectif": fields.text(string="Objectif"),
106         "commentaire": fields.text(string="Commentaire"),
107         "keywords": fields.text(string="Mots clés"),
108         "projet_id": fields.many2one("cmmi.projet",
109                                      string="Projet",
110                                      required=True),
111         "palier_id": fields.selection(_palier_selection,
112                                      string="Palier",
113                                      required=True),
114         "chantier_id": fields.selection(_chantier_selection,
115                                        string="Chantier",
116                                        required=True),
117     }