[REVERT]: Applied reverse changes for revno:3364
[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 from osv import osv, fields
23 from tools.translate import _
24
25 class base_module_upgrade(osv.osv_memory):
26     """ Module Upgrade """
27
28     _name = "base.module.upgrade"
29     _description = "Module Upgrade"
30
31     _columns = {
32         'module_info': fields.text('Modules to update',readonly=True),
33     }
34
35     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
36         """ Changes the view dynamically
37          @param self: The object pointer.
38          @param cr: A database cursor
39          @param uid: ID of the user currently logged in
40          @param context: A standard dictionary
41          @return: New arch of view.
42         """
43         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)
44         record_id = context and context.get('active_id', False) or False
45         active_model = context.get('active_model')
46         if (not record_id) or (not active_model):
47             return res
48
49         ids = self.get_module_list(cr, uid, context=context)
50         if not ids:
51             res['arch'] = '''<form string="Apply Scheduled Upgrades">
52                                 <separator string="System update completed" colspan="4"/>
53                                 <label align="0.0" string="The selected modules have been updated / installed !" colspan="4"/>
54                                 <label align="0.0" string="We suggest to reload the menu tab to see the new menus (Ctrl+T then Ctrl+R)." colspan="4"/>
55                                  <separator string="" colspan="4"/>
56                                 <newline/>
57                                 <button special="cancel" string="Close" icon="gtk-cancel"/>
58                                 <button name="config" string="Start configuration" type="object" icon="gtk-ok"/>
59                              </form>'''
60
61         return res
62
63     def get_module_list(self, cr, uid, context=None):
64         mod_obj = self.pool.get('ir.module.module')
65         ids = mod_obj.search(cr, uid, [
66             ('state', 'in', ['to upgrade', 'to remove', 'to install'])])
67         return ids
68
69     def default_get(self, cr, uid, fields, context=None):
70         """
71         This function checks for precondition before wizard executes
72         @param self: The object pointer
73         @param cr: the current row, from the database cursor,
74         @param uid: the current user’s ID for security checks,
75         @param fields: List of fields for default value
76         @param context: A standard dictionary for contextual values
77         """
78         mod_obj = self.pool.get('ir.module.module')
79         ids = self.get_module_list(cr, uid, context=context)
80         res = mod_obj.read(cr, uid, ids, ['name','state'], context)
81         return {'module_info': '\n'.join(map(lambda x: x['name']+' : '+x['state'], res))}
82
83
84     def config(self, cr, uid, ids, context=None):
85         return self.pool.get('res.config').next(cr, uid, [], context=context)
86
87 base_module_upgrade()