From 3b2a50696a14d106fe4818f52b4ad5fc609ea631 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Tue, 1 Nov 2016 18:26:40 +0100 Subject: [PATCH] fixes #587 --- database_cleanup/models/__init__.py | 1 + database_cleanup/models/ir_model_fields.py | 17 +++++++++++++++++ database_cleanup/models/purge_models.py | 1 + 3 files changed, 19 insertions(+) create mode 100644 database_cleanup/models/ir_model_fields.py diff --git a/database_cleanup/models/__init__.py b/database_cleanup/models/__init__.py index 004a4e3bb..1857ee3b0 100644 --- a/database_cleanup/models/__init__.py +++ b/database_cleanup/models/__init__.py @@ -5,3 +5,4 @@ from . import purge_columns from . import purge_tables from . import purge_data from . import purge_menus +from . import ir_model_fields diff --git a/database_cleanup/models/ir_model_fields.py b/database_cleanup/models/ir_model_fields.py new file mode 100644 index 000000000..ffb2988ac --- /dev/null +++ b/database_cleanup/models/ir_model_fields.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# © 2014-2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import api, models + + +class IrModelFields(models.Model): + _inherit = 'ir.model.fields' + + # In case of purging it means the model does not exist anymore in + # installed module. In this specific case, we need to avoid to check + # if fields can be removed as it would fail. + @api.multi + def _prepare_update(self): + if self.env.context.get('purge'): + self -= self.filtered(lambda x: x.model not in self.env.registry) + return super(IrModelFields, self)._prepare_update() diff --git a/database_cleanup/models/purge_models.py b/database_cleanup/models/purge_models.py index 996cea61d..181ccd101 100644 --- a/database_cleanup/models/purge_models.py +++ b/database_cleanup/models/purge_models.py @@ -54,6 +54,7 @@ class CleanupPurgeLineModel(models.TransientModel): context_flags = { MODULE_UNINSTALL_FLAG: True, 'no_drop_table': True, + 'purge': True, } for line in self: