summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamin Shah <jas@openerp.com>2015-08-24 12:50:06 +0530
committerThibault Delavallée <tde@openerp.com>2015-11-26 11:26:46 +0100
commit3560cf04eee4dde7683218428fc8211bb1365633 (patch)
tree06a1f9d4755ad34817e4dd498f250919e0bec096
parent60c010d30649fccd61e9ca4b2356d63e815c8c55 (diff)
[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.
-rw-r--r--addons/mail/models/mail_channel.py1
-rw-r--r--addons/mail/models/mail_thread.py7
-rw-r--r--addons/project/project.py19
-rw-r--r--addons/project_issue/project_issue.py19
4 files changed, 43 insertions, 3 deletions
diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py
index 2202a8c3ab6..b38fbcfdc44 100644
--- a/addons/mail/models/mail_channel.py
+++ b/addons/mail/models/mail_channel.py
@@ -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()
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py
index b307425337d..21b360a6b73 100644
--- a/addons/mail/models/mail_thread.py
+++ b/addons/mail/models/mail_thread.py
@@ -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
diff --git a/addons/project/project.py b/addons/project/project.py
index aeee91eb948..8f9c0c598af 100644
--- a/addons/project/project.py
+++ b/addons/project/project.py
@@ -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'
diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py
index 82c65dba563..3aaee858887 100644
--- a/addons/project_issue/project_issue.py
+++ b/addons/project_issue/project_issue.py
@@ -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"