[IMP] mail: headers to notification emails
> > This merge adds some basic data to notification emails headers. It contains the related > record of the notification. This allows users to classify / perform action based on > headers. > > Headers : > - X-Odoo-Objects: list of records > - X-Odoo-db-uuid: database uid In task and issue, we had the parent project and the tags in the headers.
This commit is contained in:
committed by
Thibault Delavallée
parent
60c010d306
commit
3560cf04ee
@@ -166,7 +166,6 @@ class Channel(models.Model):
|
||||
self.message_post(body=notification, message_type="notification", subtype="mail.mt_comment")
|
||||
return result
|
||||
|
||||
|
||||
@api.multi
|
||||
def message_get_email_values(self, notif_mail=None):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -730,8 +730,11 @@ class MailThread(models.AbstractModel):
|
||||
""" Get specific notification email values to store on the notification
|
||||
mail_mail. Void method, inherit it to add custom values. """
|
||||
self.ensure_one()
|
||||
res = dict()
|
||||
return res
|
||||
database_uuid = self.env['ir.config_parameter'].get_param('database.uuid')
|
||||
return {'headers': repr({
|
||||
'X-Odoo-Objects': "%s-%s" % (self._model, self.id),
|
||||
'X-Odoo-db-uuid': database_uuid
|
||||
})}
|
||||
|
||||
# ------------------------------------------------------
|
||||
# Mail gateway
|
||||
|
||||
@@ -9,6 +9,7 @@ from openerp import api
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp import tools
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.safe_eval import safe_eval as eval
|
||||
from openerp.tools.translate import _
|
||||
from openerp.exceptions import UserError
|
||||
|
||||
@@ -833,6 +834,24 @@ class task(osv.osv):
|
||||
data._message_add_suggested_recipient(recipients, partner=data.partner_id, reason=reason)
|
||||
return recipients
|
||||
|
||||
def message_get_email_values(self, cr, uid, ids, notif_mail=None, context=None):
|
||||
res = super(task, self).message_get_email_values(cr, uid, ids, notif_mail=notif_mail, context=context)
|
||||
current_task = self.browse(cr, uid, ids[0], context=context)
|
||||
headers = {}
|
||||
if res.get('headers'):
|
||||
try:
|
||||
headers.update(eval(res['headers']))
|
||||
except Exception:
|
||||
pass
|
||||
if current_task.project_id:
|
||||
current_objects = filter(None, headers.get('X-Odoo-Objects', '').split(','))
|
||||
current_objects.insert(0, 'project.project-%s, ' % current_task.project_id.id)
|
||||
headers['X-Odoo-Objects'] = ','.join(current_objects)
|
||||
if current_task.tag_ids:
|
||||
headers['X-Odoo-Tags'] = ','.join([tag.name for tag in current_task.tag_ids])
|
||||
res['headers'] = repr(headers)
|
||||
return res
|
||||
|
||||
|
||||
class account_analytic_account(osv.osv):
|
||||
_inherit = 'account.analytic.account'
|
||||
|
||||
@@ -12,6 +12,7 @@ from openerp import tools
|
||||
from openerp.osv import fields, osv, orm
|
||||
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from openerp.tools import html2plaintext
|
||||
from openerp.tools.safe_eval import safe_eval as eval
|
||||
from openerp.tools.translate import _
|
||||
from openerp.exceptions import UserError, AccessError
|
||||
|
||||
@@ -422,6 +423,24 @@ class project_issue(osv.Model):
|
||||
self.write(cr, SUPERUSER_ID, thread_id, {'date_action_last': fields.datetime.now()}, context=context)
|
||||
return res
|
||||
|
||||
def message_get_email_values(self, cr, uid, ids, notif_mail=None, context=None):
|
||||
res = super(project_issue, self).message_get_email_values(cr, uid, ids, notif_mail=notif_mail, context=context)
|
||||
current_issue = self.browse(cr, uid, ids[0], context=context)
|
||||
headers = {}
|
||||
if res.get('headers'):
|
||||
try:
|
||||
headers.update(eval(res['headers']))
|
||||
except Exception:
|
||||
pass
|
||||
if current_issue.project_id:
|
||||
current_objects = filter(None, headers.get('X-Odoo-Objects', '').split(','))
|
||||
current_objects.insert(0, 'project.project-%s, ' % current_issue.project_id.id)
|
||||
headers['X-Odoo-Objects'] = ','.join(current_objects)
|
||||
if current_issue.tag_ids:
|
||||
headers['X-Odoo-Tags'] = ','.join([tag.name for tag in current_issue.tag_ids])
|
||||
res['headers'] = repr(headers)
|
||||
return res
|
||||
|
||||
|
||||
class project(osv.Model):
|
||||
_inherit = "project.project"
|
||||
|
||||
Reference in New Issue
Block a user