[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) <adt@odoo.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user