02fc908392ee3b817e787884780ea4cdfe947118
[OpenERP/cmmi.git] / wizards / moe.py
1 #-*- coding: utf8 -*-
2
3 from openerp.osv import osv, fields
4
5 class ProjetMoeWizard(osv.TransientModel):
6
7     _name = "cmmi.projet.moe.wizard"
8
9     def _moes_selection(self, cr, uid, context=None):
10         model_base = self.pool.get("cmmi.mo.moe")
11         model_proj = self.pool.get("cmmi.projet.domaine")
12
13         if context is None or not context.has_key("project_id"):
14             return []
15
16         # recherche des lien entre le projet et les domaines
17         links_ids = model_proj.search(
18             cr,
19             uid,
20             [('project_id', '=', context["project_id"])],
21             context=context,
22         )
23
24         # récupérations des moes déjà sélectionnés pour le projet
25         excluded_ids = list(set([r['moe_id'][0] for r in model_proj.read(
26             cr,
27             uid,
28             links_ids,
29             fields=["moe_id"],
30             context=context
31         )]))
32
33         # recherche des domaines autres que ceux déjà sélectionnés
34         domaines_ids = model_base.search(
35             cr,
36             uid,
37             [('id', 'not in', excluded_ids)],
38             context=context,
39         )
40
41         # renvoi des 2 uplets (id, name)
42         print [(r["id"], r["name"]) for r in model_base.read(
43             cr,
44             uid,
45             domaines_ids,
46             fields=["id", "name"],
47             context=context
48         )]
49         return [(r["id"], r["name"]) for r in model_base.read(
50             cr,
51             uid,
52             domaines_ids,
53             fields=["id", "name"],
54             context=context
55         )]
56
57     _columns = {
58         "main": fields.boolean(string="Domaine principal ?"),
59         "project_id": fields.many2one("cmmi.projet",
60                                       string="Projet"),
61         "domaine_id": fields.selection(_domaines_selection,
62                                       string="Domaine"),
63     }