From 1d76129a226040d394096b73da8d3ee4cad433d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 16 Sep 2013 13:47:06 +0200 Subject: [PATCH] [FIX] mass_mailing: - fixed forgottent import of mail_thread in mass_mailing, to enable bounce and replied tracking - fixed replied computation in message_route_process, adding the original email in parameters - fixed form view of campaign, to add edit and dlete now that clicking on it redirects to the waves - added track field on mail_mail, to avoid creating too mush entries in mail.mail.statistics - fixed mass_mailign controller bzr revid: tde@openerp.com-20130916114706-b9zyhp0ha6mr9fzg --- addons/mail/mail_thread.py | 16 +++++----- addons/mass_mailing/__init__.py | 1 + addons/mass_mailing/controllers/main.py | 4 +-- addons/mass_mailing/mail_mail.py | 30 ++++++++++++------- addons/mass_mailing/mail_thread.py | 10 ++++--- addons/mass_mailing/mass_mailing_view.xml | 6 ++++ .../wizard/mail_compose_message.py | 6 ++-- 7 files changed, 47 insertions(+), 26 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 9c4d753bc1c..d72c24f6a99 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -874,9 +874,9 @@ class mail_thread(osv.AbstractModel): "No possible route found for incoming message from %s to %s (Message-Id %s:)." \ "Create an appropriate mail.alias or force the destination model." % (email_from, email_to, message_id) - def message_route_process(self, cr, uid, msg, routes, context=None): - # postpone setting msg.partner_ids after message_post, to avoid double notifications - partner_ids = msg.pop('partner_ids', []) + def message_route_process(self, cr, uid, message, message_dict, routes, context=None): + # postpone setting message_dict.partner_ids after message_post, to avoid double notifications + partner_ids = message_dict.pop('partner_ids', []) thread_id = False for model, thread_id, custom_values, user_id, alias in routes: if self._name == 'mail.thread': @@ -885,22 +885,22 @@ class mail_thread(osv.AbstractModel): model_pool = self.pool[model] assert thread_id and hasattr(model_pool, 'message_update') or hasattr(model_pool, 'message_new'), \ "Undeliverable mail with Message-Id %s, model %s does not accept incoming emails" % \ - (msg['message_id'], model) + (message_dict['message_id'], model) # disabled subscriptions during message_new/update to avoid having the system user running the # email gateway become a follower of all inbound messages nosub_ctx = dict(context, mail_create_nosubscribe=True, mail_create_nolog=True) if thread_id and hasattr(model_pool, 'message_update'): - model_pool.message_update(cr, user_id, [thread_id], msg, context=nosub_ctx) + model_pool.message_update(cr, user_id, [thread_id], message_dict, context=nosub_ctx) else: - thread_id = model_pool.message_new(cr, user_id, msg, custom_values, context=nosub_ctx) + thread_id = model_pool.message_new(cr, user_id, message_dict, custom_values, context=nosub_ctx) else: assert thread_id == 0, "Posting a message without model should be with a null res_id, to create a private message." model_pool = self.pool.get('mail.thread') if not hasattr(model_pool, 'message_post'): context['thread_model'] = model model_pool = self.pool['mail.thread'] - new_msg_id = model_pool.message_post(cr, uid, [thread_id], context=context, subtype='mail.mt_comment', **msg) + new_msg_id = model_pool.message_post(cr, uid, [thread_id], context=context, subtype='mail.mt_comment', **message_dict) if partner_ids: # postponed after message_post, because this is an external message and we don't want to create @@ -972,7 +972,7 @@ class mail_thread(osv.AbstractModel): # find possible routes for the message routes = self.message_route(cr, uid, msg_txt, msg, model, thread_id, custom_values, context=context) - thread_id = self.message_route_process(cr, uid, msg, routes, context=context) + thread_id = self.message_route_process(cr, uid, msg_txt, msg, routes, context=context) return thread_id def message_new(self, cr, uid, msg_dict, custom_values=None, context=None): diff --git a/addons/mass_mailing/__init__.py b/addons/mass_mailing/__init__.py index f7b250bd2ed..9dadc456842 100644 --- a/addons/mass_mailing/__init__.py +++ b/addons/mass_mailing/__init__.py @@ -21,5 +21,6 @@ import mass_mailing import mail_mail +import mail_thread import wizard import controllers diff --git a/addons/mass_mailing/controllers/main.py b/addons/mass_mailing/controllers/main.py index 9997d854cf3..3ca238256b1 100644 --- a/addons/mass_mailing/controllers/main.py +++ b/addons/mass_mailing/controllers/main.py @@ -8,5 +8,5 @@ class MassMailController(http.Controller): def track_mail_open(self, mail_id): """ Email tracking. """ mail_mail_stats = request.registry.get('mail.mail.statistics') - mail_mail_stats.set_opened(request.cr, request.uid, mail_ids=[mail_id]) - return False + mail_mail_stats.set_opened(request.cr, request.uid, mail_mail_ids=[mail_id]) + return "data:image/gif;base64,R0lGODlhAQABAIAAANvf7wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" diff --git a/addons/mass_mailing/mail_mail.py b/addons/mass_mailing/mail_mail.py index 5d576c158a9..e288e5cf1bb 100644 --- a/addons/mass_mailing/mail_mail.py +++ b/addons/mass_mailing/mail_mail.py @@ -23,7 +23,7 @@ from urlparse import urljoin from openerp import tools from openerp import SUPERUSER_ID -from openerp.osv import osv +from openerp.osv import osv, fields class MailMail(osv.Model): @@ -31,16 +31,25 @@ class MailMail(osv.Model): _name = 'mail.mail' _inherit = ['mail.mail'] + _columns = { + 'track': fields.boolean('Use tracking'), + } + + _defaults = { + 'track': False, + } + def create(self, cr, uid, values, context=None): """ Override mail_mail creation to create an entry in mail.mail.statistics """ # TDE note: should be after 'all values computed', to have values (FIXME after merging other branch holding create refactoring) mail_id = super(MailMail, self).create(cr, uid, values, context=context) - message_id = self.browse(cr, SUPERUSER_ID, mail_id).message_id - self.pool['mail.mail.statistics'].create( - cr, uid, { - 'mail_mail_id': mail_id, - 'message_id': message_id, - }, context=context) + mail = self.browse(cr, SUPERUSER_ID, mail_id) + if mail.track: + self.pool['mail.mail.statistics'].create( + cr, uid, { + 'mail_mail_id': mail_id, + 'message_id': mail.message_id, + }, context=context) return mail_id def _get_tracking_url(self, cr, uid, mail, partner=None, context=None): @@ -53,7 +62,8 @@ class MailMail(osv.Model): body = super(MailMail, self).send_get_mail_body(cr, uid, mail, partner=partner, context=context) # generate tracking URL - tracking_url = self._get_tracking_url(cr, uid, mail, partner, context=context) - if tracking_url: - body = tools.append_content_to_html(body, tracking_url, plaintext=False, container_tag='div') + if mail.track: + tracking_url = self._get_tracking_url(cr, uid, mail, partner, context=context) + if tracking_url: + body = tools.append_content_to_html(body, tracking_url, plaintext=False, container_tag='div') return body diff --git a/addons/mass_mailing/mail_thread.py b/addons/mass_mailing/mail_thread.py index 292e13eab3a..985d03ce2cc 100644 --- a/addons/mass_mailing/mail_thread.py +++ b/addons/mass_mailing/mail_thread.py @@ -22,6 +22,7 @@ import logging from openerp import tools +from openerp.addons.mail.mail_message import decode from openerp.addons.mail.mail_thread import decode_header from openerp.osv import osv @@ -76,7 +77,8 @@ class MailThread(osv.Model): for obj in self.browse(cr, uid, ids, context=context): self.write(cr, uid, [obj.id], {'message_bounce': obj.message_bounce + 1}, context=context) - def message_route_process(self, cr, uid, msg, routes, context=None): - if msg.get('message_id'): - self.pool['mail.mail.statistics'].set_replied(cr, uid, mail_message_ids=[msg.get('message_id')], context=context) - return super(MailThread, self).message_route_process(cr, uid, msg, routes, context=context) + def message_route_process(self, cr, uid, message, message_dict, routes, context=None): + if message.get('References'): + message_ids = [x.strip() for x in decode(message['References']).split()] + self.pool['mail.mail.statistics'].set_replied(cr, uid, mail_message_ids=message_ids, context=context) + return super(MailThread, self).message_route_process(cr, uid, message, message_dict, routes, context=context) diff --git a/addons/mass_mailing/mass_mailing_view.xml b/addons/mass_mailing/mass_mailing_view.xml index f7443c896e3..b7128f8e7dd 100644 --- a/addons/mass_mailing/mass_mailing_view.xml +++ b/addons/mass_mailing/mass_mailing_view.xml @@ -251,6 +251,12 @@
i
diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py index dd4aa632a9e..6c02357c1bf 100644 --- a/addons/mass_mailing/wizard/mail_compose_message.py +++ b/addons/mass_mailing/wizard/mail_compose_message.py @@ -37,10 +37,10 @@ class MailComposeMessage(osv.TransientModel): ), } - def render_message_batch(self, cr, uid, wizard, res_ids, context=None): + def get_mail_values(self, cr, uid, wizard, res_ids, context=None): """ Override method that generated the mail content by adding the mass mailing campaign, when doing pure email mass mailing. """ - res = super(MailComposeMessage, self).render_message_batch(cr, uid, wizard, res_ids, context=context) + res = super(MailComposeMessage, self).get_mail_values(cr, uid, wizard, res_ids, context=context) if wizard.composition_mode == 'mass_mail' and wizard.mass_mailing_campaign_id: # TODO: which kind of mass mailing ? current_date = fields.datetime.now() mass_mailing_id = self.pool['mail.mass_mailing'].create( @@ -52,4 +52,6 @@ class MailComposeMessage(osv.TransientModel): 'template_id': wizard.template_id and wizard.template_id.id or False, }, context=context) context['default_mass_mailing_id'] = mass_mailing_id + for res_id in res_ids: + res[res_id]['track'] = True return res