From d583b98a9731118c123df2a99006ef24e0eacef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 24 Aug 2012 18:10:38 +0200 Subject: [PATCH] [IMP] mail_followers: moved email creation for emails send for notification into a dedicated method; updated subject and body creation (added default subject, added signature on body). bzr revid: tde@openerp.com-20120824161038-vhylgsify9f9xder --- addons/mail/mail_followers.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py index 72dd3519ace..2045df49d70 100644 --- a/addons/mail/mail_followers.py +++ b/addons/mail/mail_followers.py @@ -71,19 +71,13 @@ class mail_notification(osv.Model): def notify(self, cr, uid, partner_ids, msg_id, context=None): """ Send by email the notification depending on the user preferences """ context = context or {} - partner_obj = self.pool.get('res.partner') mail_mail_obj = self.pool.get('mail.mail') - notification_obj = self.pool.get('mail.notification') msg_obj = self.pool.get('mail.message') msg = msg_obj.browse(cr, uid, msg_id, context=context) - towrite = { - 'email_to': [], - 'subject': msg.subject, - 'body': msg.body, - } + towrite = self.notify_get_notif_email_dict(cr, uid, msg, context=context) - for partner in partner_obj.browse(cr, uid, partner_ids, context=context): + for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context): # Do not send an email to the writer if partner.user_id.id == uid: continue @@ -98,9 +92,7 @@ class mail_notification(osv.Model): if partner.email not in towrite['email_to']: towrite['email_to'].append(partner.email) - if towrite.get('state') and not context.get('noemail'): - if towrite.get('subject'): - towrite['subject'] = msg.name_get()[0][1] + if towrite.get('state') and not context.get('mail_noemail'): towrite['message_id'] = msg.id towrite['email_to'] = ', '.join(towrite['email_to']) @@ -108,3 +100,18 @@ class mail_notification(osv.Model): mail_mail_obj.send(cr, uid, [email_notif_id], context=context) return True + + def notify_get_notif_email_dict(self, cr, uid, msg, context=None): + """ Return the content of the email send for notification. + :param message: browse record on source mail.message + """ + subject = msg.subject or '%s posted a comment on %s' % (msg.author_id.name, msg.record_name) + body = msg.body + author_signature = msg.author_id.user_ids[0].signature + if author_signature: + body += '
%s
' % (author_signature) + return { + 'email_to': [], + 'subject': subject, + 'body': body, + }