1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
23 from osv import osv, fields
24 from tools.translate import _
26 class base_module_upgrade(osv.osv_memory):
27 """ Module Upgrade """
29 _name = "base.module.upgrade"
30 _description = "Module Upgrade"
33 'module_info': fields.text('Modules to update',readonly=True),
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.
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):
50 ids = self.get_module_list(cr, uid, context=context)
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"/>
58 <button special="cancel" string="Close" icon="gtk-cancel"/>
59 <button name="config" string="Start configuration" type="object" icon="gtk-ok"/>
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'])])
70 def default_get(self, cr, uid, fields, context=None):
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
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))}
84 def upgrade_module(self, cr, uid, ids, context=None):
85 mod_obj = self.pool.get('ir.module.module')
86 data_obj = self.pool.get('ir.model.data')
87 # process to install and upgrade modules
88 ids = mod_obj.search(cr, uid, [('state', 'in', ['to upgrade', 'to install'])])
90 mod_dep_obj = self.pool.get('ir.module.module.dependency')
91 for mod in mod_obj.browse(cr, uid, ids):
92 depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)])
93 for dep_mod in mod_dep_obj.browse(cr, uid, depends_mod_ids):
94 if dep_mod.state in ('unknown','uninstalled'):
95 unmet_packages.append(dep_mod.name)
96 if len(unmet_packages):
97 raise osv.except_osv(_('Unmet dependency !'), _('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages)))
98 mod_obj.download(cr, uid, ids, context=context)
100 # process to remove modules
101 remove_module_ids = mod_obj.search(cr, uid, [('state', 'in', ['to remove'])])
102 mod_obj.module_uninstall(cr, uid, remove_module_ids, context)
104 _db, pool = pooler.restart_pool(cr.dbname, update_module=True)
106 id2 = data_obj._get_id(cr, uid, 'base', 'view_base_module_upgrade_install')
108 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
113 'res_model': 'base.module.upgrade',
114 'views': [(id2, 'form')],
116 'type': 'ir.actions.act_window',
120 def config(self, cr, uid, ids, context=None):
121 return self.pool.get('res.config').next(cr, uid, [], context=context)
123 base_module_upgrade()
125 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: