From 8d7e0cefc08d8f2d2e7345f3d173f6d230fb8191 Mon Sep 17 00:00:00 2001 From: Rahul Prajapati Date: Mon, 29 May 2023 13:15:03 +0000 Subject: [PATCH] [FIX] base: unlink custom cron after uninstalling model When user uninstalls a module it doesn't unlinks custom crons which are created by user and it will keep running in the background and will generate traceback. So, to fix this we unlink all the custom crons which are related to the module being uninstalled. sentry-3929309220 closes odoo/odoo#124175 X-original-commit: b0202488220bd48dd177e9e0601f2f3ba8d7a0f1 Signed-off-by: Fabien Pinckaers Signed-off-by: Rahul Prajapati (rapr) --- odoo/addons/base/models/ir_actions.py | 2 +- odoo/addons/base/models/ir_model.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_actions.py b/odoo/addons/base/models/ir_actions.py index d36eb59e4ff..7957510e502 100644 --- a/odoo/addons/base/models/ir_actions.py +++ b/odoo/addons/base/models/ir_actions.py @@ -463,7 +463,7 @@ class IrActionsServer(models.Model): sequence = fields.Integer(default=5, help="When dealing with multiple actions, the execution order is " "based on the sequence. Low number means high priority.") - model_id = fields.Many2one('ir.model', string='Model', required=True, ondelete='cascade', + model_id = fields.Many2one('ir.model', string='Model', required=True, ondelete='cascade', index=True, help="Model on which the server action runs.") model_name = fields.Char(related='model_id.model', string='Model Name', readonly=True, store=True) # Python code diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 17e953328fe..9a7f5864a9d 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -319,6 +319,11 @@ class IrModel(models.Model): # delete fields whose comodel is being removed self.env['ir.model.fields'].search([('relation', 'in', self.mapped('model'))]).unlink() + # delete ir_crons created by user + crons = self.env['ir.cron'].with_context(active_test=False).search([('model_id', 'in', self.ids)]) + if crons: + crons.unlink() + self._drop_table() res = super(IrModel, self).unlink()