Wizard Evolution : Ajout d'une fonction pour la selection d'un chantier
[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         project_id = context.get('project_id', False)
14         if project_id:
15             res['project_id'] = project_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["projet_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.palier")
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["projet_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
78     _columns = {
79         "projet_id": fields.many2one("cmmi.projet",
80                                      string="Projet",
81                                      required=True),
82         "palier_id": fields.selection(_palier_selection,
83                                      string="Palier",
84                                      required=True),
85         "chantier_id": fields.selection(_chantier_selection,
86                                        string="Chantier",
87                                        required=True),
88     }