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