summaryrefslogtreecommitdiff
path: root/odoo/addons/base/models/ir_module.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-01-14 10:34:50 +0100
committerChristophe Simonis <chs@odoo.com>2019-01-14 10:34:50 +0100
commit3cbc9dd6c034f8bbba8a75def07d063e3f625bdb (patch)
tree55d7e9b940e27a1dad5415b6b721ab464d0bc418 /odoo/addons/base/models/ir_module.py
parent976429c8c69b2225e96ccb0e254ee4849832ed27 (diff)
parent6a0675d36dd888daa4183f3d609ce334ed3cb493 (diff)
[MERGE] forward port branch 12.0 up to 6a0675d36dd
Diffstat (limited to 'odoo/addons/base/models/ir_module.py')
-rw-r--r--odoo/addons/base/models/ir_module.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/odoo/addons/base/models/ir_module.py b/odoo/addons/base/models/ir_module.py
index 824365424cc..e673ac016dd 100644
--- a/odoo/addons/base/models/ir_module.py
+++ b/odoo/addons/base/models/ir_module.py
@@ -22,7 +22,9 @@ import lxml.html
import odoo
from odoo import api, fields, models, modules, tools, _
+from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
from odoo.exceptions import AccessDenied, UserError
+from odoo.osv import expression
from odoo.tools.parse_version import parse_version
from odoo.tools.misc import topological_sort
from odoo.http import request
@@ -454,10 +456,25 @@ class Module(models.Model):
"""
modules_to_remove = self.mapped('name')
self.env['ir.model.data']._module_data_uninstall(modules_to_remove)
+ self._remove_copied_views()
self.write({'state': 'uninstalled', 'latest_version': False})
return True
@api.multi
+ def _remove_copied_views(self):
+ """ Remove the copies of the views installed by the modules in `self`.
+
+ Those copies do not have an external id so they will not be cleaned by
+ `_module_data_uninstall`. This is why we rely on `key` instead.
+
+ It is important to remove these copies because using them will crash if
+ they rely on data that don't exist anymore if the module is removed.
+ """
+ domain = expression.OR([[('key', '=like', m.name + '.%')] for m in self])
+ orphans = self.env['ir.ui.view'].with_context(**{'active_test': False, MODULE_UNINSTALL_FLAG: True}).search(domain)
+ orphans.unlink()
+
+ @api.multi
@api.returns('self')
def downstream_dependencies(self, known_deps=None,
exclude_states=('uninstalled', 'uninstallable', 'to remove')):