From f59b251a129b7b6c6b009ca47ff23e2b19e029e5 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 9 Jun 2015 14:42:27 +0200 Subject: [PATCH] [FIX] cope with purging nonexisting models --- database_cleanup/model/purge_models.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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'