[FIX] mass_mailing: fixed bouncing tracking
mail_mail now have a statistics_ids field, allowing to create statistics when creating a mail.mail. This is done in the mail composer, using classic o2m command. Mail_mail create is overrided to ipdate the statistics value (message_id) that is computed directly in the create and not accessible in the values dict. Added model and res_id on stat model, to allow message_bounce update, without havign to rely on the mail.mail existence. bzr revid: tde@openerp.com-20130917094218-7jz5mnldogzhlioh
This commit is contained in:
parent
a2d167bd0a
commit
643996de2b
|
@ -32,24 +32,20 @@ class MailMail(osv.Model):
|
|||
_inherit = ['mail.mail']
|
||||
|
||||
_columns = {
|
||||
'track': fields.boolean('Use tracking'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'track': False,
|
||||
'statistics_ids': fields.one2many(
|
||||
'mail.mail.statistics', 'mail_mail_id',
|
||||
string='Statistics',
|
||||
),
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
if values.get('statistics_ids'):
|
||||
mail = self.browse(cr, SUPERUSER_ID, mail_id)
|
||||
for stat in mail.statistics_ids:
|
||||
self.pool['mail.mail.statistics'].write(cr, uid, [stat.id], {'message_id': mail.message_id}, context=context)
|
||||
return mail_id
|
||||
|
||||
def _get_tracking_url(self, cr, uid, mail, partner=None, context=None):
|
||||
|
@ -62,7 +58,7 @@ class MailMail(osv.Model):
|
|||
body = super(MailMail, self).send_get_mail_body(cr, uid, mail, partner=partner, context=context)
|
||||
|
||||
# generate tracking URL
|
||||
if mail.track:
|
||||
if mail.statistics_ids:
|
||||
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')
|
||||
|
|
|
@ -46,14 +46,10 @@ class MailThread(osv.Model):
|
|||
bounce_match = tools.bounce_re.search(email_to)
|
||||
if bounce_match:
|
||||
bounced_mail_id = bounce_match.group(1)
|
||||
self.pool['mail.mail'].set_bounced(cr, uid, [bounced_mail_id], context=context)
|
||||
if self.pool['mail.mail'].exists(cr, uid, bounced_mail_id):
|
||||
mail = self.pool['mail.mail'].browse(cr, uid, bounced_mail_id, context=context)
|
||||
bounced_model = mail.model
|
||||
bounced_thread_id = mail.res_id
|
||||
else:
|
||||
bounced_model = bounce_match.group(2)
|
||||
bounced_thread_id = int(bounce_match.group(3)) if bounce_match.group(3) else 0
|
||||
stat_ids = self.pool['mail.mail.statistics'].set_bounced(cr, uid, mail_mail_ids=[bounced_mail_id], context=context)
|
||||
for stat in self.pool['mail.mail.statistics'].browse(cr, uid, stat_ids, context=context):
|
||||
bounced_model = stat.model
|
||||
bounced_thread_id = stat.res_id
|
||||
_logger.info('Routing mail from %s to %s with Message-Id %s: bounced mail from mail %s, model: %s, thread_id: %s',
|
||||
email_from, email_to, message_id, bounced_mail_id, bounced_model, bounced_thread_id)
|
||||
if bounced_model and bounced_model in self.pool and hasattr(self.pool[bounced_model], 'message_receive_bounce'):
|
||||
|
|
|
@ -288,7 +288,13 @@ class MailMailStats(osv.Model):
|
|||
'the related mail_mail can be deleted separately from its statistics.'
|
||||
),
|
||||
'message_id': fields.char(
|
||||
'Message-ID', required=True,
|
||||
'Message-ID',
|
||||
),
|
||||
'model': fields.char(
|
||||
'Document model',
|
||||
),
|
||||
'res_id': fields.integer(
|
||||
'Document ID',
|
||||
),
|
||||
# campaign / wave data
|
||||
'mass_mailing_id': fields.many2one(
|
||||
|
@ -333,7 +339,7 @@ class MailMailStats(osv.Model):
|
|||
for stat in self.browse(cr, uid, ids, context=context):
|
||||
if not stat.opened:
|
||||
self.write(cr, uid, [stat.id], {'opened': fields.datetime.now()}, context=context)
|
||||
return True
|
||||
return ids
|
||||
|
||||
def set_replied(self, cr, uid, ids=None, mail_mail_ids=None, mail_message_ids=None, context=None):
|
||||
""" Set as replied """
|
||||
|
@ -346,7 +352,7 @@ class MailMailStats(osv.Model):
|
|||
for stat in self.browse(cr, uid, ids, context=context):
|
||||
if not stat.replied:
|
||||
self.write(cr, uid, [stat.id], {'replied': fields.datetime.now()}, context=context)
|
||||
return True
|
||||
return ids
|
||||
|
||||
def set_bounced(self, cr, uid, ids=None, mail_mail_ids=None, mail_message_ids=None, context=None):
|
||||
""" Set as bounced """
|
||||
|
@ -359,4 +365,4 @@ class MailMailStats(osv.Model):
|
|||
for stat in self.browse(cr, uid, ids, context=context):
|
||||
if not stat.bounced:
|
||||
self.write(cr, uid, [stat.id], {'bounced': fields.datetime.now()}, context=context)
|
||||
return True
|
||||
return ids
|
||||
|
|
|
@ -317,6 +317,7 @@
|
|||
<field name="message_id"/>
|
||||
<field name="opened"/>
|
||||
<field name="replied"/>
|
||||
<field name="bounced"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -332,6 +333,8 @@
|
|||
<field name="opened"/>
|
||||
<field name="replied"/>
|
||||
<field name="bounced"/>
|
||||
<field name="model"/>
|
||||
<field name="res_id"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
|
|
@ -53,5 +53,5 @@ class MailComposeMessage(osv.TransientModel):
|
|||
}, context=context)
|
||||
context['default_mass_mailing_id'] = mass_mailing_id
|
||||
for res_id in res_ids:
|
||||
res[res_id]['track'] = True
|
||||
res[res_id]['statistics_ids'] = [(0, 0, {'model': wizard.model, 'res_id': res_id})]
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue