23aa4363d7ed16a1cc6a0f7f5eaece1d7b2da1cf
[odoo/odoo.git] / addons / base_setup / __init__.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import installer
23 import todo
24 import wizard
25
26 from osv import fields, osv
27 import netsvc
28 from tools.translate import _
29
30 class base_setup_config_choice(osv.osv_memory):
31     """
32     """
33     _name = 'base.setup.config'
34     logger = netsvc.Logger()
35
36     def get_users(self, cr, uid, context={}):
37         user_obj = self.pool.get('res.users')
38         user_ids = user_obj.search(cr, uid, [])
39         users = user_obj.browse(cr, uid, user_ids)
40         user_str = '\n'.join(map(lambda x: '    - %s: %s / %s' % (x.name, x.login, x.password), users))
41         return _('The following users have been installed on your database: \n')+ user_str
42
43     _columns = {
44         'installed_users':fields.text('Installed Users')
45         }
46
47     _defaults = {
48         'installed_users':get_users
49         }
50
51     def set_default_menu(self, cr, uid, menu, context=None):
52         user = self.pool.get('res.users')\
53                         .browse(cr, uid, uid, context=context)
54
55         user.write({'action_id': menu.id,
56                     'menu_id': menu.id})
57
58     def get_default_menu(self, cr, uid, context=None):
59         actions = self.pool.get('ir.actions.act_window')
60
61         current_menu_id = actions.search(cr, uid, [('name','=','Menu')],
62                                          context=context)
63         assert len(current_menu_id) == 1,\
64                'A given user should only have one menu item'
65         return actions.browse(cr, uid, current_menu_id[0], context=context)
66
67     def menu(self, cr, uid, ids, context=None):
68         menu = self.get_default_menu(cr, uid, context=context)
69         self.set_default_menu(cr, uid, menu, context=context)
70
71         if menu.view_id.id:
72             view_id = (menu.view_id.id, menu.view_id.name)
73         else:
74             view_id = False
75
76         return {
77             'name': menu.name,
78             'type': menu.type,
79             'view_id': view_id,
80             'domain': menu.domain,
81             'res_model': menu.res_model,
82             'src_model': menu.src_model,
83             'view_type': menu.view_type,
84             'view_mode': menu.view_mode,
85             'views': menu.views,
86         }
87
88     def config(self, cr, uid, ids, context=None):
89         menu = self.get_default_menu(cr, uid, context=context)
90         self.set_default_menu(cr, uid, menu, context=context)
91
92         return self.pool.get('res.config').next(cr, uid, [], context=context)
93
94 base_setup_config_choice()
95
96
97 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
98