[FIX] base.module.upgrade: fix fields_view_get overload
[odoo/odoo.git] / openerp / addons / base / module / wizard / base_module_upgrade.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 pooler
23 from osv import osv, fields
24 from tools.translate import _
25
26 class base_module_upgrade(osv.osv_memory):
27     """ Module Upgrade """
28
29     _name = "base.module.upgrade"
30     _description = "Module Upgrade"
31
32     _columns = {
33         'module_info': fields.text('Modules to update',readonly=True),
34     }
35
36     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
37         """ Changes the view dynamically
38          @param self: The object pointer.
39          @param cr: A database cursor
40          @param uid: ID of the user currently logged in
41          @param context: A standard dictionary
42          @return: New arch of view.
43         """
44         res = super(base_module_upgrade, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
45         if view_type != 'form':
46             return res
47
48         record_id = context and context.get('active_id', False) or False
49         active_model = context.get('active_model')
50         if (not record_id) or (not active_model):
51             return res
52
53         ids = self.get_module_list(cr, uid, context=context)
54         if not ids:
55             res['arch'] = '''<form string="Apply Scheduled Upgrades">
56                                 <separator string="System update completed" colspan="4"/>
57                                 <label align="0.0" string="The selected modules have been updated / installed !" colspan="4"/>
58                                 <label align="0.0" string="We suggest to reload the menu tab to see the new menus (Ctrl+T then Ctrl+R)." colspan="4"/>
59                                  <separator string="" colspan="4"/>
60                                 <newline/>
61                                 <button special="cancel" string="Close" icon="gtk-cancel"/>
62                                 <button name="config" string="Start configuration" type="object" icon="gtk-ok"/>
63                              </form>'''
64
65         return res
66
67     def get_module_list(self, cr, uid, context=None):
68         mod_obj = self.pool.get('ir.module.module')
69         ids = mod_obj.search(cr, uid, [
70             ('state', 'in', ['to upgrade', 'to remove', 'to install'])])
71         return ids
72
73     def default_get(self, cr, uid, fields, context=None):
74         """
75         This function checks for precondition before wizard executes
76         @param self: The object pointer
77         @param cr: the current row, from the database cursor,
78         @param uid: the current user’s ID for security checks,
79         @param fields: List of fields for default value
80         @param context: A standard dictionary for contextual values
81         """
82         mod_obj = self.pool.get('ir.module.module')
83         ids = self.get_module_list(cr, uid, context=context)
84         res = mod_obj.read(cr, uid, ids, ['name','state'], context)
85         return {'module_info': '\n'.join(map(lambda x: x['name']+' : '+x['state'], res))}
86
87     def upgrade_module(self, cr, uid, ids, context=None):
88         mod_obj = self.pool.get('ir.module.module')
89         ids = mod_obj.search(cr, uid, [('state', 'in', ['to upgrade', 'to remove', 'to install'])])
90         unmet_packages = []
91         mod_dep_obj = self.pool.get('ir.module.module.dependency')
92         for mod in mod_obj.browse(cr, uid, ids):
93             depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)])
94             for dep_mod in mod_dep_obj.browse(cr, uid, depends_mod_ids):
95                 if dep_mod.state in ('unknown','uninstalled'):
96                     unmet_packages.append(dep_mod.name)
97         if len(unmet_packages):
98             raise osv.except_osv(_('Unmet dependency !'), _('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages)))
99         mod_obj.download(cr, uid, ids, context=context)
100         cr.commit()
101         _db, pool = pooler.restart_pool(cr.dbname, update_module=True)
102
103         data_obj = pool.get('ir.model.data')
104         id2 = data_obj._get_id(cr, uid, 'base', 'view_base_module_upgrade_install')
105         if id2:
106             id2 = data_obj.browse(cr, uid, id2, context=context).res_id
107
108         return {
109                 'view_type': 'form',
110                 'view_mode': 'form',
111                 'res_model': 'base.module.upgrade',
112                 'views': [(id2, 'form')],
113                 'view_id': False,
114                 'type': 'ir.actions.act_window',
115                 'target': 'new',
116             }
117
118     def config(self, cr, uid, ids, context=None):
119         return self.pool.get('res.config').next(cr, uid, [], context=context)
120
121 base_module_upgrade()
122
123 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: