From cddddf00783ed79e33fb7add830327f66361a0ce Mon Sep 17 00:00:00 2001 From: fw-bot Date: Thu, 24 Oct 2019 14:26:00 +0000 Subject: [PATCH] [FIX] mail: avoid raising errors during uninstall Raising a python error cannot stop an uninstall, however since the unlink stops early, the calls to super() are never reached, this prevents the deletion of module-related data and leaves crap in the database, not to mention that it potentially prevents the reinstallation of a module because of duplicate data with unique IDs, which is the case for mail. With this patch, we let the registry delete everything related to the mail module when uninstalling, which allows for its reinstallation. Fixes #25138 closes odoo/odoo#39347 Signed-off-by: Adrian Torres (adt) --- addons/mail/models/mail_activity.py | 3 ++- addons/mail/models/mail_channel.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index c8085802faf..8fc502ee6de 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -10,6 +10,7 @@ import pytz from odoo import api, exceptions, fields, models, _ from odoo.tools.misc import clean_context +from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG _logger = logging.getLogger(__name__) @@ -91,7 +92,7 @@ class MailActivityType(models.Model): activity_type.initial_res_model_id = activity_type.res_model_id def unlink(self): - if any(self.get_external_id().values()): + if any(self.get_external_id().values()) and not self._context.get(MODULE_UNINSTALL_FLAG): raise exceptions.ValidationError("You can not delete activity type that are used as master data.") return super(MailActivityType, self).unlink() diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 255b601ddbd..a2f211c3fa0 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -11,6 +11,7 @@ from odoo import _, api, fields, models, modules, tools from odoo.exceptions import UserError, ValidationError from odoo.osv import expression from odoo.tools import ormcache, formataddr +from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG MODERATION_FIELDS = ['moderation', 'moderator_ids', 'moderation_ids', 'moderation_notify', 'moderation_notify_msg', 'moderation_guidelines', 'moderation_guidelines_msg'] _logger = logging.getLogger(__name__) @@ -227,7 +228,7 @@ class Channel(models.Model): all_emp_group = self.env.ref('mail.channel_all_employees') except ValueError: all_emp_group = None - if all_emp_group and all_emp_group in self: + if all_emp_group and all_emp_group in self and not self._context.get(MODULE_UNINSTALL_FLAG): raise UserError(_('You cannot delete those groups, as the Whole Company group is required by other modules.')) res = super(Channel, self).unlink() # Cascade-delete mail aliases as well, as they should not exist without the mail.channel.