diff --git a/database_cleanup/model/purge_data.py b/database_cleanup/model/purge_data.py
index bcab2d832..f3e1b63cd 100644
--- a/database_cleanup/model/purge_data.py
+++ b/database_cleanup/model/purge_data.py
@@ -82,8 +82,8 @@ class CleanupPurgeWizardData(orm.TransientModel):
SELECT id FROM ir_model_data
WHERE model = %%s
AND res_id IS NOT NULL
- AND res_id NOT IN (
- SELECT id FROM %s)
+ AND NOT EXISTS (
+ SELECT id FROM %s WHERE id=ir_model_data.res_id)
""" % self.pool[model]._table, (model,))
data_ids += [data_row[0] for data_row in cr.fetchall()]
data_ids += data_pool.search(
diff --git a/database_cleanup/model/purge_models.py b/database_cleanup/model/purge_models.py
index 1aff2dc3d..415f10489 100644
--- a/database_cleanup/model/purge_models.py
+++ b/database_cleanup/model/purge_models.py
@@ -34,6 +34,26 @@ class IrModel(orm.Model):
return True
return super(IrModel, self)._drop_table(cr, uid, ids, context=context)
+ def _inherited_models(self, cr, uid, ids, field_name, arg, context=None):
+ """this function crashes for undefined models"""
+ result = dict((i, []) for i in ids)
+ existing_model_ids = [
+ this.id for this in self.browse(cr, uid, ids, context=context)
+ if self.pool.get(this.model)
+ ]
+ super_result = super(IrModel, self)._inherited_models(
+ cr, uid, existing_model_ids, field_name, arg, context=context)
+ result.update(super_result)
+ return result
+
+ def _register_hook(self, cr):
+ # patch the function field instead of overwriting it
+ if self._columns['inherited_model_ids']._fnct !=\
+ self._inherited_models.__func__:
+ self._columns['inherited_model_ids']._fnct =\
+ self._inherited_models.__func__
+ return super(IrModel, self)._register_hook(cr)
+
class CleanupPurgeLineModel(orm.TransientModel):
_inherit = 'cleanup.purge.line'
diff --git a/database_cleanup/model/purge_modules.py b/database_cleanup/model/purge_modules.py
index 12734d157..d371b5f05 100644
--- a/database_cleanup/model/purge_modules.py
+++ b/database_cleanup/model/purge_modules.py
@@ -23,6 +23,44 @@ from openerp import pooler
from openerp.osv import orm, fields
from openerp.modules.module import get_module_path
from openerp.tools.translate import _
+from openerp.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG
+
+
+class IrModelConstraint(orm.Model):
+ _inherit = 'ir.model.constraint'
+
+ def _module_data_uninstall(self, cr, uid, ids, context=None):
+ """this function crashes for constraints on undefined models"""
+ for this in self.browse(cr, uid, ids, context=context):
+ if not self.pool.get(this.model.model):
+ ids.remove(this.id)
+ this.unlink()
+ return super(IrModelConstraint, self)._module_data_uninstall(
+ cr, uid, ids, context=context)
+
+
+class IrModelData(orm.Model):
+ _inherit = 'ir.model.data'
+
+ def _module_data_uninstall(self, cr, uid, modules_to_remove, context=None):
+ """this function crashes for xmlids on undefined models or fields
+ referring to undefined models"""
+ if context is None:
+ context = {}
+ ids = self.search(cr, uid, [('module', 'in', modules_to_remove)])
+ for this in self.browse(cr, uid, ids, context=context):
+ if this.model == 'ir.model.fields':
+ ctx = context.copy()
+ ctx[MODULE_UNINSTALL_FLAG] = True
+ field = self.pool[this.model].browse(
+ cr, uid, this.res_id, context=ctx)
+ if not self.pool.get(field.model):
+ this.unlink()
+ continue
+ if not self.pool.get(this.model):
+ this.unlink()
+ return super(IrModelData, self)._module_data_uninstall(
+ cr, uid, modules_to_remove, context=context)
class CleanupPurgeLineModule(orm.TransientModel):
diff --git a/database_cleanup/model/purge_wizard.py b/database_cleanup/model/purge_wizard.py
index 5003c4aef..8629eb0b3 100644
--- a/database_cleanup/model/purge_wizard.py
+++ b/database_cleanup/model/purge_wizard.py
@@ -26,6 +26,7 @@ from openerp.osv import orm, fields
class CleanupPurgeLine(orm.AbstractModel):
""" Abstract base class for the purge wizard lines """
_name = 'cleanup.purge.line'
+ _order = 'name'
_columns = {
'name': fields.char('Name', size=256, readonly=True),
'purged': fields.boolean('Purged', readonly=True),
diff --git a/database_cleanup/view/purge_columns.xml b/database_cleanup/view/purge_columns.xml
index 40ed4a4f6..96aa1212e 100644
--- a/database_cleanup/view/purge_columns.xml
+++ b/database_cleanup/view/purge_columns.xml
@@ -25,12 +25,24 @@
-
+
Purge columns
- ir.actions.act_window
- cleanup.purge.wizard.column
- form
- form
+ ir.actions.server
+ code
+
+
+wizard_id = self.create(cr, uid, {}, context=context)
+action = {
+ 'type': 'ir.actions.act_window',
+ 'views': [(False, 'form')],
+ 'res_model': 'cleanup.purge.wizard.column',
+ 'res_id': wizard_id,
+ 'flags': {
+ 'action_buttons': False,
+ 'sidebar': False,
+ },
+}
+
diff --git a/database_cleanup/view/purge_data.xml b/database_cleanup/view/purge_data.xml
index e749f4569..890d0d450 100644
--- a/database_cleanup/view/purge_data.xml
+++ b/database_cleanup/view/purge_data.xml
@@ -25,12 +25,24 @@
-
+
Purge data entries that refer to missing resources
- ir.actions.act_window
- cleanup.purge.wizard.data
- form
- form
+ ir.actions.server
+ code
+
+
+wizard_id = self.create(cr, uid, {}, context=context)
+action = {
+ 'type': 'ir.actions.act_window',
+ 'views': [(False, 'form')],
+ 'res_model': 'cleanup.purge.wizard.data',
+ 'res_id': wizard_id,
+ 'flags': {
+ 'action_buttons': False,
+ 'sidebar': False,
+ },
+}
+
diff --git a/database_cleanup/view/purge_models.xml b/database_cleanup/view/purge_models.xml
index 0ae1d20e8..2dc25c74c 100644
--- a/database_cleanup/view/purge_models.xml
+++ b/database_cleanup/view/purge_models.xml
@@ -24,12 +24,24 @@
-
+
Purge models
- ir.actions.act_window
- cleanup.purge.wizard.model
- form
- form
+ ir.actions.server
+ code
+
+
+wizard_id = self.create(cr, uid, {}, context=context)
+action = {
+ 'type': 'ir.actions.act_window',
+ 'views': [(False, 'form')],
+ 'res_model': 'cleanup.purge.wizard.model',
+ 'res_id': wizard_id,
+ 'flags': {
+ 'action_buttons': False,
+ 'sidebar': False,
+ },
+}
+
diff --git a/database_cleanup/view/purge_modules.xml b/database_cleanup/view/purge_modules.xml
index 7c0151f54..65dd5473a 100644
--- a/database_cleanup/view/purge_modules.xml
+++ b/database_cleanup/view/purge_modules.xml
@@ -24,12 +24,24 @@
-
+
Purge modules
- ir.actions.act_window
- cleanup.purge.wizard.module
- form
- form
+ ir.actions.server
+ code
+
+
+wizard_id = self.create(cr, uid, {}, context=context)
+action = {
+ 'type': 'ir.actions.act_window',
+ 'views': [(False, 'form')],
+ 'res_model': 'cleanup.purge.wizard.module',
+ 'res_id': wizard_id,
+ 'flags': {
+ 'action_buttons': False,
+ 'sidebar': False,
+ },
+}
+
diff --git a/database_cleanup/view/purge_tables.xml b/database_cleanup/view/purge_tables.xml
index dc9ddd8f5..b963a2f02 100644
--- a/database_cleanup/view/purge_tables.xml
+++ b/database_cleanup/view/purge_tables.xml
@@ -24,12 +24,24 @@
-
+
Purge tables
- ir.actions.act_window
- cleanup.purge.wizard.table
- form
- form
+ ir.actions.server
+ code
+
+
+wizard_id = self.create(cr, uid, {}, context=context)
+action = {
+ 'type': 'ir.actions.act_window',
+ 'views': [(False, 'form')],
+ 'res_model': 'cleanup.purge.wizard.table',
+ 'res_id': wizard_id,
+ 'flags': {
+ 'action_buttons': False,
+ 'sidebar': False,
+ },
+}
+