[FIX] mail: missing 'nice' reply_to is back on track.
bzr revid: tde@openerp.com-20130318150252-twwxoborz8ppeh6a
This commit is contained in:
parent
6bbc658f9b
commit
bcc7fcb3c6
|
@ -88,13 +88,38 @@ class mail_mail(osv.Model):
|
|||
context = dict(context, default_type=None)
|
||||
return super(mail_mail, self).default_get(cr, uid, fields, context=context)
|
||||
|
||||
def _get_reply_to(self, cr, uid, values, context=None):
|
||||
""" Return a specific reply_to: alias of the document through message_get_reply_to
|
||||
or take the email_from
|
||||
"""
|
||||
if values.get('reply_to'):
|
||||
return values.get('reply_to')
|
||||
email_reply_to = False
|
||||
|
||||
# if model and res_id: try to use ``message_get_reply_to`` that returns the document alias
|
||||
if values.get('model') and values.get('res_id') and hasattr(self.pool.get(values.get('model')), 'message_get_reply_to'):
|
||||
email_reply_to = self.pool.get(values.get('model')).message_get_reply_to(cr, uid, [values.get('res_id')], context=context)[0]
|
||||
# no alias reply_to -> reply_to will be the email_from, only the email part
|
||||
if not email_reply_to and values.get('email_from'):
|
||||
emails = tools.email_split(values.get('email_from'))
|
||||
if emails:
|
||||
email_reply_to = emails[0]
|
||||
|
||||
# format 'Document name <email_address>'
|
||||
if email_reply_to and values.get('model') and values.get('res_id'):
|
||||
document_name = self.pool.get(values.get('model')).name_get(cr, SUPERUSER_ID, [values.get('res_id')], context=context)[0]
|
||||
if document_name:
|
||||
email_reply_to = _('Followers of %s <%s>') % (document_name[1], email_reply_to)
|
||||
|
||||
return email_reply_to
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
# notification field: if not set, set if mail comes from an existing mail.message
|
||||
if 'notification' not in values and values.get('mail_message_id'):
|
||||
values['notification'] = True
|
||||
if not values.get('reply_to') and values.get('res_id') and values.get('model') and hasattr(self.pool.get(values.get('model')), 'message_get_reply_to'):
|
||||
values['reply_to'] = self.pool.get(values.get('model')).message_get_reply_to(cr, uid, [values.get('res_id')], context=context)[0]
|
||||
elif not values.get('reply_to'):
|
||||
values['reply_to'] = values.get('email_from', False)
|
||||
# reply_to: if not set, set with default values that require creation values
|
||||
if not values.get('reply_to'):
|
||||
values['reply_to'] = self._get_reply_to(cr, uid, values, context=context)
|
||||
return super(mail_mail, self).create(cr, uid, values, context=context)
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
@ -207,33 +232,6 @@ class mail_mail(osv.Model):
|
|||
body = tools.append_content_to_html(body, body_footer, plaintext=False, container_tag='div')
|
||||
return body
|
||||
|
||||
def send_get_mail_reply_to(self, cr, uid, mail, partner=None, context=None):
|
||||
""" Return a specific ir_email reply_to.
|
||||
|
||||
:param browse_record mail: mail.mail browse_record
|
||||
:param browse_record partner: specific recipient partner
|
||||
"""
|
||||
if mail.reply_to:
|
||||
return mail.reply_to
|
||||
email_reply_to = False
|
||||
|
||||
# if model and res_id: try to use ``message_get_reply_to`` that returns the document alias
|
||||
if mail.model and mail.res_id and hasattr(self.pool.get(mail.model), 'message_get_reply_to'):
|
||||
email_reply_to = self.pool.get(mail.model).message_get_reply_to(cr, uid, [mail.res_id], context=context)[0]
|
||||
# no alias reply_to -> reply_to will be the email_from, only the email part
|
||||
if not email_reply_to and mail.email_from:
|
||||
emails = tools.email_split(mail.email_from)
|
||||
if emails:
|
||||
email_reply_to = emails[0]
|
||||
|
||||
# format 'Document name <email_address>'
|
||||
if email_reply_to and mail.model and mail.res_id:
|
||||
document_name = self.pool.get(mail.model).name_get(cr, SUPERUSER_ID, [mail.res_id], context=context)[0]
|
||||
if document_name:
|
||||
email_reply_to = _('Followers of %s <%s>') % (document_name[1], email_reply_to)
|
||||
|
||||
return email_reply_to
|
||||
|
||||
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None):
|
||||
""" Return a dictionary for specific email values, depending on a
|
||||
partner, or generic to the whole recipients given by mail.email_to.
|
||||
|
|
Loading…
Reference in New Issue