From 718d38f056295879cf19261315fdf225afe9b942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 28 Feb 2013 17:40:54 +0100 Subject: [PATCH] [FIX] Chatter: mail_post_autofollow can be completed with mail_post_autofollow_partner_ids, that filters the recipients to subscribe. Purpose: suggested partners are added as followers, not people that could have been added after in the compose wizard. bzr revid: tde@openerp.com-20130228164054-e3y3pdrygqph0dm2 --- addons/mail/mail_thread.py | 5 ++++- addons/mail/res_partner.py | 9 ++++++++- addons/mail/static/src/js/mail.js | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 67a61dab7f7..282675e8859 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -970,7 +970,10 @@ class mail_thread(osv.AbstractModel): # automatically subscribe recipients if asked to if context.get('mail_post_autofollow') and thread_id and partner_ids: - self.message_subscribe(cr, uid, [thread_id], list(partner_ids), context=context) + partner_to_subscribe = partner_ids + if context.get('mail_post_autofollow_partner_ids'): + partner_to_subscribe = filter(lambda item: item in context.get('mail_post_autofollow_partner_ids'), partner_ids) + self.message_subscribe(cr, uid, [thread_id], list(partner_to_subscribe), context=context) # _mail_flat_thread: automatically set free messages to the first posted message if self._mail_flat_thread and not parent_id and thread_id: diff --git a/addons/mail/res_partner.py b/addons/mail/res_partner.py index 77f680bcab2..f2dde7e65d9 100644 --- a/addons/mail/res_partner.py +++ b/addons/mail/res_partner.py @@ -18,9 +18,10 @@ # along with this program. If not, see . # ############################################################################## - +from openerp.tools.translate import _ from openerp.osv import fields, osv + class res_partner_mail(osv.Model): """ Update partner to add a field about notification preferences """ _name = "res.partner" @@ -42,6 +43,12 @@ class res_partner_mail(osv.Model): 'notification_email_send': lambda *args: 'comment' } + def message_get_suggested_recipients(self, cr, uid, ids, context=None): + recipients = super(res_partner_mail, self).message_get_suggested_recipients(cr, uid, ids, context=context) + for partner in self.browse(cr, uid, ids, context=context): + self._message_add_suggested_recipient(recipients, partner, partner=partner, reason=_('Customer')) + return recipients + def message_post(self, cr, uid, thread_id, **kwargs): """ Override related to res.partner. In case of email message, set it as private: diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f86f1d5d077..0d78cb4fd76 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -550,6 +550,7 @@ openerp.mail = function (session) { 'default_attachment_ids': self.attachment_ids, 'default_partner_ids': partner_ids, 'mail_post_autofollow': true, + 'mail_post_autofollow_partner_ids': partner_ids, }; if (self.is_log) { _.extend(context, {'mail_compose_log': true}); @@ -708,7 +709,10 @@ openerp.mail = function (session) { 'parent_id': this.context.default_parent_id, 'attachment_ids': _.map(this.attachment_ids, function (file) {return file.id;}), 'partner_ids': partner_ids, - 'context': _.extend(this.parent_thread.context, {'mail_post_autofollow': true}), + 'context': _.extend(this.parent_thread.context, { + 'mail_post_autofollow': true, + 'mail_post_autofollow_partner_ids': partner_ids, + }), 'type': 'comment', 'content_subtype': 'plaintext', };