From 8a7dc813af050d6402029b2d8345b7bd4c7c86de Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 27 Feb 2019 10:38:50 +0000 Subject: [PATCH] [FIX] base: copied views are delete too early Install Invoicing (account) and uninstall it. It results to a an error because some views required by `payment.acquirer` are deleted before the acquirers. The problem is due to the way copied views are deleted, since 1388b7f they are removed before the module uninstallation. The related commit faced a similar problem where copied views were deleted too late during a module uninstallation. The two problems are revealing that the copied views have to be removed as part of the module uninstallation, more precisely after all records refering to them has been deleted but before the schemas has been cleaned. opw-1943286 closes odoo/odoo#31443 Signed-off-by: Raphael Collet (rco) --- odoo/addons/base/models/ir_model.py | 10 +++++++++- odoo/addons/base/models/ir_module.py | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 4a59c5d4249..da31a2ae8b8 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -1594,9 +1594,17 @@ class IrModelData(models.Model): # Remove non-model records first, then model fields, and finish with models undeletable += unlink_if_refcount(item for item in to_unlink if item[0] not in ('ir.model', 'ir.model.fields', 'ir.model.constraint')) + + # Remove copied views. This must happen after removing all records from + # the modules to remove, otherwise ondelete='restrict' may prevent the + # deletion of some view. This must also happen before cleaning up the + # database schema, otherwise some dependent fields may no longer exist + # in database. + modules = self.env['ir.module.module'].search([('name', 'in', modules_to_remove)]) + modules._remove_copied_views() + undeletable += unlink_if_refcount(item for item in to_unlink if item[0] == 'ir.model.constraint') - modules = self.env['ir.module.module'].search([('name', 'in', modules_to_remove)]) constraints = self.env['ir.model.constraint'].search([('module', 'in', modules.ids)]) constraints._module_data_uninstall() diff --git a/odoo/addons/base/models/ir_module.py b/odoo/addons/base/models/ir_module.py index 82b8b4e3cee..dc1f7bedd27 100644 --- a/odoo/addons/base/models/ir_module.py +++ b/odoo/addons/base/models/ir_module.py @@ -457,7 +457,6 @@ class Module(models.Model): tables, columns, constraints, etc. """ modules_to_remove = self.mapped('name') - self._remove_copied_views() self.env['ir.model.data']._module_data_uninstall(modules_to_remove) # we deactivate prefetching to not try to read a column that has been deleted self.with_context(prefetch_fields=False).write({'state': 'uninstalled', 'latest_version': False})