From 9b9bdae9e008e930eaf1cf208b90f66bdbdf4e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 6 Sep 2012 15:42:01 +0200 Subject: [PATCH] [IMP] composer: attachments are attached to the mail.compose.message record, not the related document anymore. This way, when deleting the mail.compose.message, attachments will be unlinked. Added deletion cascaded to res_model and res_id = 0, because of attachments added on a not-already-saved composer. BTW, cleaned mail/__openerp__.py. bzr revid: tde@openerp.com-20120906134201-8845xov0mjbxh8mr --- addons/mail/__openerp__.py | 12 ++++++------ addons/mail/mail_message.py | 9 +++++---- addons/mail/static/src/xml/mail.xml | 4 ++-- addons/mail/wizard/mail_compose_message.py | 2 ++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/mail/__openerp__.py b/addons/mail/__openerp__.py index 99dd6bda6ac..08a98cb0a02 100644 --- a/addons/mail/__openerp__.py +++ b/addons/mail/__openerp__.py @@ -30,27 +30,27 @@ A business oriented Social Networking with a fully-integrated email and message =========================================================================================== The Social Networking module provides an unified social network -abstraction layer allowing applications to display a complete +abstraction layer allowing applications to display a complete communication history on documents. It gives the users the possibility to read and send messages and emails in an unified way. -It also provides a feeds page combined to a subscription mechanism, that +It also provides a feeds page combined to a subscription mechanism, that allows to follow documents, and to be constantly updated about recent news. - + The main features of the module are: ------------------------------------ * a clean and renewed communication history for any OpenERP document that can act as a discussion topic, * a discussion mean on documents, - * a subscription mechanism to be updated about new messages on + * a subscription mechanism to be updated about new messages on interesting documents, - * an unified feeds page to see recent messages and activity + * an unified feeds page to see recent messages and activity on followed documents, * user communication through the feeds page, * a threaded discussion design, * relies on the global outgoing mail server, an integrated email - management system allowing to send emails with a configurable + management system allowing to send emails with a configurable scheduler-based processing engine * includes an extensible generic email composition assistant, that can turn into a mass-mailing assistant, and is capable of interpreting diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index c76d073c12b..5fa9b8c45d7 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -306,11 +306,12 @@ class mail_message(osv.Model): def unlink(self, cr, uid, ids, context=None): # cascade-delete attachments that are directly attached to the message (should only happen - # for mail.messages that act as parent for a standalone mail.mail record. + # for mail.messages that act as parent for a standalone mail.mail record). Also remove + # attachment with a void id, because this can happen with the composer. attachments_to_delete = [] - for mail in self.browse(cr, uid, ids, context=context): - for attach in mail.attachment_ids: - if attach.res_model == self._name and attach.res_id == mail.id: + for message in self.browse(cr, uid, ids, context=context): + for attach in message.attachment_ids: + if attach.res_model == self._name and (attach.res_id == message.id or attach.res_id == 0): attachments_to_delete.append(attach.id) if attachments_to_delete: self.pool.get('ir.attachment').unlink(cr, uid, attachments_to_delete, context=context) diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 49e861ac870..161c5e2fcbc 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -81,8 +81,8 @@ /web/binary/upload_attachment - - + + diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index b62cb11aee2..a112e82b590 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -262,6 +262,8 @@ class mail_compose_message(osv.TransientModel): post_values.update(email_dict) # post the message active_model_pool.message_post(cr, uid, [res_id], type='comment', context=context, **post_values) + # post process: update attachments, because id is not necessarily known when adding attachments in Chatter + self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], {'res_id': wizard.id}, context=context) return {'type': 'ir.actions.act_window_close'}