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