From 59eee6ba5fed0ba74221f44a296ec6efedbc2527 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Fri, 8 Nov 2019 20:33:25 +0000 Subject: [PATCH] [IMP] base_import_module: clean up after itself Uninstalling an imported module leaves behind an ir.module.module entry which is entirely useless: it cannot be reinstalled without re-uploading the module. A quick solution is provided here by simply cleaning up after the uninstallation and deleting the ir.module.module records of imported modules that just got removed. Another possibility could be to store the uploaded module for good in an attachment and re-load it from there upon re-installation, but that would lead to some conflict with Studio, as uninstalling the studio_customization module usually means you want to get rid of it for good. --- addons/base_import_module/models/ir_module.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/base_import_module/models/ir_module.py b/addons/base_import_module/models/ir_module.py index a9d064ad23a..9fff8448ffd 100644 --- a/addons/base_import_module/models/ir_module.py +++ b/addons/base_import_module/models/ir_module.py @@ -146,6 +146,19 @@ class IrModule(models.Model): r.append("Error while importing module '%s'.\n\n %s \n Make sure those modules are installed and try again." % (mod, error)) return '\n'.join(r), module_names + def module_uninstall(self): + # Delete an ir_module_module record completely if it was an imported + # one. The rationale behind this is that an imported module *cannot* be + # reinstalled anyway, as it requires the data files. Any attempt to + # install it again will simply fail without trace. + res = super().module_uninstall() + modules_to_delete = self.filtered('imported') + if modules_to_delete: + _logger.info("deleting imported modules upon uninstallation: %s", + ", ".join(modules_to_delete.mapped('name'))) + modules_to_delete.unlink() + return res + def _is_studio_custom(path): """