From 8007db3bc1725333aa059f6445336bbd6b8e201f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 16 Nov 2012 12:28:00 +0100 Subject: [PATCH] [FIX] mail_thread: when posting a messure using mail_thread as model (typically, a private message without model, res_id), do not try to set it on the attachments; this make the custom access rules check of ir.attachment crash. bzr revid: tde@openerp.com-20121116112800-8ur8yr8alcrlgg1z --- addons/mail/mail_thread.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index c5da22297f9..f0216436679 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -767,13 +767,19 @@ class mail_thread(osv.AbstractModel): # 3. Post-processing # HACK TDE FIXME: Chatter: attachments linked to the document (not done JS-side), load the message if attachment_ids: + # TDE FIXME (?): when posting a private message, we use mail.thread as a model + # However, attaching doc to mail.thread is not possible, mail.thread does not have any table + model = self._name + if model == 'mail.thread': + model = False filtered_attachment_ids = ir_attachment.search(cr, SUPERUSER_ID, [ ('res_model', '=', 'mail.compose.message'), ('res_id', '=', 0), ('create_uid', '=', uid), ('id', 'in', attachment_ids)], context=context) if filtered_attachment_ids: - ir_attachment.write(cr, SUPERUSER_ID, attachment_ids, {'res_model': self._name, 'res_id': thread_id}, context=context) + if thread_id and model: + ir_attachment.write(cr, SUPERUSER_ID, attachment_ids, {'res_model': model, 'res_id': thread_id}, context=context) mail_message.write(cr, SUPERUSER_ID, [new_message_id], {'attachment_ids': [(6, 0, [pid for pid in attachment_ids])]}, context=context) return new_message_id