From 148efe9c55e42ba83bc92d07e49e78e470a5a17d Mon Sep 17 00:00:00 2001
From: pinky <>
Date: Thu, 28 Dec 2006 11:06:46 +0000
Subject: [PATCH] BASE: Function to remove installed modules
bzr revid: pinky-b26b2a3b41980a56a595a294b8915b74c9b35728
---
bin/addons/__init__.py | 24 +++++++++++++++++++++++-
bin/addons/base/module/module.py | 16 +++++++++++++++-
bin/addons/base/module/module_view.xml | 4 ++--
3 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py
index cb57399806d..184b5509d1c 100644
--- a/bin/addons/__init__.py
+++ b/bin/addons/__init__.py
@@ -233,10 +233,10 @@ def register_classes():
imp.load_module(m, *imp.find_module(m))
def load_modules(db, force_demo=False, status={}, update_module=False):
+ cr = db.cursor()
force = []
if force_demo:
force.append('demo')
- cr = db.cursor()
if update_module:
cr.execute("select name from ir_module_module where state in ('installed', 'to install', 'to upgrade')")
else:
@@ -244,6 +244,28 @@ def load_modules(db, force_demo=False, status={}, update_module=False):
module_list = [name for (name,) in cr.fetchall()]
graph = create_graph(module_list, force)
load_module_graph(cr, graph, status)
+ pool = pooler.get_pool(cr.dbname)
+ if update_module:
+ cr.execute("select id,name from ir_module_module where state in ('to remove')")
+ for mod_id, mod_name in cr.fetchall():
+ cr.execute('select model,res_id from ir_model_data where not noupdate and module=%s order by id desc', (mod_name,))
+ for rmod,rid in cr.fetchall():
+ mod_table = pool.get(rmod)._table
+ print rmod, mod_table
+ cr.execute('delete from '+mod_table+' where id=%d', (rid,))
+ cr.commit()
+ #
+ # TODO: remove menu without actions of childs
+ #
+ cr.execute('''delete from
+ ir_ui_menu
+ where
+ (id not in (select parent_id from ir_ui_menu where parent_id is not null))
+ and
+ (id not in (select res_id from ir_values where model='ir.ui.menu'))''')
+
+ cr.execute("update ir_module_module set state=%s where state in ('to remove')", ('uninstalled', ))
+ cr.commit()
cr.commit()
cr.close()
diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py
index ea73b96580d..80728e03d60 100644
--- a/bin/addons/base/module/module.py
+++ b/bin/addons/base/module/module.py
@@ -30,7 +30,7 @@ import re
import urllib
import os
import tools
-from osv import fields, osv
+from osv import fields, osv, orm
class module_repository(osv.osv):
_name = "ir.module.repository"
@@ -135,6 +135,20 @@ class module(osv.osv):
return True
def button_uninstall(self, cr, uid, ids, context={}):
+ for module in self.browse(cr, uid, ids):
+ cr.execute('''select m.state,m.name
+ from
+ ir_module_module_dependency d
+ join
+ ir_module_module m on (d.module_id=m.id)
+ where
+ d.name=%s and
+ m.state not in ('uninstalled','uninstallable','to remove')''', (module.name,))
+ res = cr.fetchall()
+ if res:
+ print 'Error !'
+ print 'The module you are trying to remove depends on installed modules :\n' + '\n'.join(map(lambda x: '\t%s: %s' % (x[0], x[1]), res))
+ raise orm.except_orm('Error', 'The module you are trying to remove depends on installed modules :\n' + '\n'.join(map(lambda x: '\t%s: %s' % (x[0], x[1]), res)))
self.write(cr, uid, ids, {'state': 'to remove'})
return True
diff --git a/bin/addons/base/module/module_view.xml b/bin/addons/base/module/module_view.xml
index 29f1d867d9c..1b83d8dda38 100644
--- a/bin/addons/base/module/module_view.xml
+++ b/bin/addons/base/module/module_view.xml
@@ -89,10 +89,10 @@
+
-