summaryrefslogtreecommitdiff
path: root/bin/addons/base/module/wizard/base_module_upgrade.py
diff options
context:
space:
mode:
authorrpa (Open ERP) <rpa@tinyerp.com>2010-09-03 11:09:27 +0530
committerrpa (Open ERP) <rpa@tinyerp.com>2010-09-03 11:09:27 +0530
commit1bb23ce2e36ef28922f8133c25fc0dda45e18e01 (patch)
tree3f88e40d38eb12d9c6c59e1439bea14e014c2256 /bin/addons/base/module/wizard/base_module_upgrade.py
parent2790fa06bc126062bd8926c0e2ac705eab5fb1e7 (diff)
parent8e8cb549251b6914a34a729bb06c02462ed95af9 (diff)
[MERGE]: Merge with lp:~openerp-dev/openobject-server/ksa-dev-framework for osv_memory wizards
bzr revid: rpa@tinyerp.com-20100903053927-xvr7ourv9rgmvt4t
Diffstat (limited to 'bin/addons/base/module/wizard/base_module_upgrade.py')
-rw-r--r--bin/addons/base/module/wizard/base_module_upgrade.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/bin/addons/base/module/wizard/base_module_upgrade.py b/bin/addons/base/module/wizard/base_module_upgrade.py
new file mode 100644
index 00000000000..e51fe24503f
--- /dev/null
+++ b/bin/addons/base/module/wizard/base_module_upgrade.py
@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import pooler
+import os
+import tools
+from osv import osv, fields
+
+class base_module_upgrade(osv.osv_memory):
+ """ Module Upgrade """
+
+ _name = "base.module.upgrade"
+ _description = "Module Upgrade"
+
+ _columns = {
+ 'module_info': fields.text('Modules to update',readonly=True),
+ }
+
+ def default_get(self, cr, uid, fields, context=None):
+ """
+ This function checks for precondition before wizard executes
+ @param self: The object pointer
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks,
+ @param fields: List of fields for default value
+ @param context: A standard dictionary for contextual values
+
+ """
+ mod_obj = self.pool.get('ir.module.module')
+ data_obj = self.pool.get('ir.model.data')
+ ids = mod_obj.search(cr, uid, [
+ ('state', 'in', ['to upgrade', 'to remove', 'to install'])])
+ res = mod_obj.read(cr, uid, ids, ['name','state'], context)
+ return {'module_info': '\n'.join(map(lambda x: x['name']+' : '+x['state'], res))}
+
+ def upgrade_module(self, cr, uid, ids, context):
+ pool = pooler.get_pool(cr.dbname)
+ mod_obj = self.pool.get('ir.module.module')
+ data_obj = self.pool.get('ir.model.data')
+ ids = mod_obj.search(cr, uid, [('state', 'in', ['to upgrade', 'to remove', 'to install'])])
+ unmet_packages = []
+ mod_dep_obj = pool.get('ir.module.module.dependency')
+ for mod in mod_obj.browse(cr, uid, ids):
+ depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)])
+ for dep_mod in mod_dep_obj.browse(cr, uid, depends_mod_ids):
+ if dep_mod.state in ('unknown','uninstalled'):
+ unmet_packages.append(dep_mod.name)
+ if len(unmet_packages):
+ raise wizard.except_wizard('Unmet dependency !', 'Following modules are uninstalled or unknown. \n\n'+'\n'.join(unmet_packages))
+ mod_obj.download(cr, uid, ids, context=context)
+ cr.commit()
+ db, pool = pooler.restart_pool(cr.dbname, update_module=True)
+
+ id2 = data_obj._get_id(cr, uid, 'base', 'view_base_module_upgrade_install')
+ if id2:
+ id2 = data_obj.browse(cr, uid, id2, context=context).res_id
+
+ return {
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'base.module.upgrade',
+ 'views': [(id2, 'form')],
+ 'view_id': False,
+ 'type': 'ir.actions.act_window',
+ 'target': 'new',
+ }
+
+ def config(self, cr, uid, ids, context=None):
+ return self.pool.get('res.config').next(cr, uid, [], context=context)
+
+base_module_upgrade()