Imrpovement in wizards
[odoo/odoo.git] / addons / profile_service / profile_service.py
1 ##############################################################################
2 #
3 # Copyright (c) 2004-2008 Tiny SPRL (http://tiny.be) All Rights Reserved.
4 #
5 # $Id: __terp__.py 8595 2008-06-16 13:00:21Z stw $
6 #
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
12 # Service Company
13 #
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 ###############################################################################
28
29 from osv import fields, osv
30 import pooler
31
32 ##class config_install_extra_modules(osv.osv_memory):
33 ##    _name='config.install_extra_modules'
34 ##    def _get_uninstall_modules(self,cr,uid,context=None):
35 ##        module_obj=self.pool.get('ir.module.module')
36 ##        line_obj=self.pool.get('config.install_extra_modules.line')
37 ##        uninstall_module_ids=module_obj.search(cr,uid,[('state', 'in', ['uninstalled', 'uninstallable'])])
38 ##        res=[]
39 ##        for id in uninstall_module_ids:
40 ##            res.append(line_obj.create(cr,uid,{'module_id':id},context=None))
41 ##        print res
42 ##        return res
43 ##    _columns = {
44 ##        'name':fields.char('Name', size=64),
45 ##        'module_ids':fields.one2many('config.install_extra_modules.line', 'config_id', 'Modules'),
46 ##
47 ##    }
48 ##    _defaults={
49 ##       'module_ids':_get_uninstall_modules
50 ##    }
51 ##    def action_install(self, cr, uid, ids, context=None):
52 ##        res=self.read(cr,uid,ids)[0]
53 ##        mod_obj = self.pool.get('ir.module.module')
54 ##        line_obj=self.pool.get('config.install_extra_modules.line')
55 ##        if 'module_ids' in res:
56 ##            module_ids=res['module_ids']
57 ##            lines=line_obj.read(cr,uid,module_ids)
58 ##            for line in lines:
59 ##                if 'install' in line and 'module_id' and line and line['install']:
60 ##                    mod_obj.download(cr, uid, [line['module_id']], context=context)
61 ##                    cr.commit()
62 ##                    db, pool = pooler.restart_pool(cr.dbname, update_module=True)
63 ##        return {
64 ##                'view_type': 'form',
65 ##                "view_mode": 'form',
66 ##                'res_model': 'ir.module.module.configuration.wizard',
67 ##                'type': 'ir.actions.act_window',
68 ##                'target':'new',
69 ##            }
70 ##
71 ##config_install_extra_modules()
72 #
73 #class config_install_extra_modules_line(osv.osv_memory):
74 #    _name='config.install_extra_modules.line'
75 #    _columns = {
76 #        'name':fields.char('Name', size=64),
77 #        'install':fields.boolean('Install'),
78 #        'config_id': fields.many2one('config.install_extra_modules', 'Configuration Module Wizard'),
79 #        'module_id':fields.many2one('ir.module.module', 'Module',readonly=True,required=True),
80 #
81 #    }
82 #
83 #
84 #config_install_extra_modules_line()
85
86 class config_install_extra_modules(osv.osv_memory):
87     _name='config.install_extra_modules'
88     _columns = {
89         'name':fields.char('Name', size=64),
90         'timesheets_module':fields.boolean('Timesheets Management'),
91         'holidays_module':fields.boolean('Hollidays Management'),
92
93     }
94     def action_cancel(self,cr,uid,ids,conect=None):
95         return {
96                 'view_type': 'form',
97                 "view_mode": 'form',
98                 'res_model': 'ir.module.module.configuration.wizard',
99                 'type': 'ir.actions.act_window',
100                 'target':'new',
101          }
102     def action_install(self, cr, uid, ids, context=None):
103         res=self.read(cr,uid,ids)[0]
104         mod_obj = self.pool.get('ir.module.module')
105         if 'timesheets_module' in res and res['timesheets_module']:
106             ids = mod_obj.search(cr, uid, [('name', '=', 'hr_timesheet')])
107             mod_obj.download(cr, uid, ids, context=context)
108             cr.commit()
109             #db, pool = pooler.restart_pool(cr.dbname, update_module=True)
110         if  'hr_holidays_module' in res and res['hr_holidays_module']:
111             ids = mod_obj.search(cr, uid, [('name', '=', 'hr_holidays')])
112             mod_obj.download(cr, uid, ids, context=context)
113             cr.commit()
114             #db, pool = pooler.restart_pool(cr.dbname, update_module=True)
115         return {
116                 'view_type': 'form',
117                 "view_mode": 'form',
118                 'res_model': 'ir.module.module.configuration.wizard',
119                 'type': 'ir.actions.act_window',
120                 'target':'new',
121             }
122
123 config_install_extra_modules()