Skip to content
Snippets Groups Projects
Commit 262e0010 authored by Julien (juc) Castiaux's avatar Julien (juc) Castiaux
Browse files

[FIX] mail: delete messages on module uninstallation

When uninstalling a module, the messages linked to the records
of that module are not deleted leading to ghost messages when
reinstalling the module.

This is due to the lack of foreign keys in the definition of the
chatter making it impossible to cascade delete.

opw-1928208

closes odoo/odoo#30798
parent 17461127
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,24 @@ class IrModel(models.Model):
)
def unlink(self):
# Delete followers for models that will be unlinked.
# Delete followers, messages and attachments for models that will be unlinked.
models = tuple(self.mapped('model'))
query = "DELETE FROM mail_followers WHERE res_model IN %s"
self.env.cr.execute(query, [tuple(self.mapped('model'))])
self.env.cr.execute(query, [models])
query = "DELETE FROM mail_message WHERE model in %s"
self.env.cr.execute(query, [models])
query = """
DELETE FROM ir_attachment
WHERE res_model in %s
RETURNING store_fname
"""
self.env.cr.execute(query, [models])
for (fname,) in self.env.cr.fetchall():
self.env['ir.attachment']._file_delete(fname)
return super(IrModel, self).unlink()
@api.multi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment