From c5f01ad903c4a032a04786e4619c5d008c0932fb Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 16 Mar 2012 14:30:26 +0100 Subject: [PATCH] [FIX] mail.message: when auto-deleting a message, only delete attachments it owns There's a peculiar way to manage attachments on mail messages, as there is an explicit many2many on top of regular attachments like for any record, so it is possible to link a mail to attachments that are owned by other records. Such attachments must not be deleted along with the message when the auto-delete flag is set. bzr revid: odo@openerp.com-20120316133026-4wbrwx64nqkeyaou --- addons/mail/mail_message.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index d4ea41fedfe..98c88a3cc8c 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -521,7 +521,9 @@ class mail_message(osv.osv): message.refresh() if message.state == 'sent' and message.auto_delete: self.pool.get('ir.attachment').unlink(cr, uid, - [x.id for x in message.attachment_ids], + [x.id for x in message.attachment_ids \ + if x.res_model == self._name and \ + x.res_id == message.id], context=context) message.unlink() except Exception: