diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-07-17 09:26:42 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-07-17 15:39:06 +0000 |
| commit | 2896aad34e797b6ca65a8efe3c5d71f31500a9a2 (patch) | |
| tree | 81f2298b04182860e84f2ca9815f313cc0c75ffc /addons/mass_mailing/models/mail_mail.py | |
| parent | 20dfba6e11ac4553509c1a3516c6453b8f8023e7 (diff) | |
[REF] mass_mailing: rename mail.mail.statistics and reporting model
PURPOSE
Mass mailing is currently a bit messy. As SMS will be added as a way to notify
people in mass through SMS let us take this opportunity to somehow clean this
application: organization, light code cleaning, model renaming.
SPECIFICATIONS
Rename mail.mail.statistics to mailing.trace and mail.statistics.report
to mail.trace.report. Rationale :
* mail.mail.statistics is linked to mail.mail model. Soon this model will
hold data related to SMS sending. It makes sense to be broader in the
naming;
* mailing.trace is more inlined with marketing.trace model that is the
marketing automation model using it in marketing automation (enterprise
application);
* mailing.trace is shorter to write;
* mail.statistics.report model should sense to be updated at the same
time;
MIGRATION
mail.mail.statistics model -> mailing.trace
mail_mail_statistics table -> mailing_trace
mail.statistics.report model -> mail.trace.report
fields updated (w column change)
* link.tracker.click: mail_stat_id -> mailing_trace_id
fields updated (no column change)
* mail.mail: statistics_ids -> mailing_trace_ids
* mail.mass_mailing: statistics_ids -> mailing_trace_ids
LINKS
Task ID 2037906
Preparing task ID 1997464 (SMS addition in mass mailing)
PR #34938
Diffstat (limited to 'addons/mass_mailing/models/mail_mail.py')
| -rw-r--r-- | addons/mass_mailing/models/mail_mail.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/addons/mass_mailing/models/mail_mail.py b/addons/mass_mailing/models/mail_mail.py index a4de6be6972..1dcb643b1e7 100644 --- a/addons/mass_mailing/models/mail_mail.py +++ b/addons/mass_mailing/models/mail_mail.py @@ -14,16 +14,16 @@ class MailMail(models.Model): _inherit = ['mail.mail'] mailing_id = fields.Many2one('mail.mass_mailing', string='Mass Mailing') - statistics_ids = fields.One2many('mail.mail.statistics', 'mail_mail_id', string='Statistics') + mailing_trace_ids = fields.One2many('mailing.trace', 'mail_mail_id', string='Statistics') @api.model def create(self, values): - """ Override mail_mail creation to create an entry in mail.mail.statistics """ + """ Override mail_mail creation to create an entry in mailing.trace """ # TDE note: should be after 'all values computed', to have values (FIXME after merging other branch holding create refactoring) mail = super(MailMail, self).create(values) - if values.get('statistics_ids'): + if values.get('mailing_trace_ids'): mail_sudo = mail.sudo() - mail_sudo.statistics_ids.write({'message_id': mail_sudo.message_id, 'state': 'outgoing'}) + mail_sudo.mailing_trace_ids.write({'message_id': mail_sudo.message_id, 'state': 'outgoing'}) return mail def _get_tracking_url(self): @@ -54,12 +54,12 @@ class MailMail(models.Model): def _send_prepare_body(self): """ Override to add the tracking URL to the body and to add - Statistic_id in shorted urls """ + trace ID in shortened urls """ # TDE: temporary addition (mail was parameter) due to semi-new-API self.ensure_one() body = super(MailMail, self)._send_prepare_body() - if self.mailing_id and body and self.statistics_ids: + if self.mailing_id and body and self.mailing_trace_ids: for match in re.findall(URL_REGEX, self.body_html): href = match[0] url = match[1] @@ -67,7 +67,7 @@ class MailMail(models.Model): parsed = werkzeug.urls.url_parse(url, scheme='http') if parsed.scheme.startswith('http') and parsed.path.startswith('/r/'): - new_href = href.replace(url, url + '/m/' + str(self.statistics_ids[0].id)) + new_href = href.replace(url, url + '/m/' + str(self.mailing_trace_ids[0].id)) body = body.replace(href, new_href) # generate tracking URL @@ -96,8 +96,8 @@ class MailMail(models.Model): mail_sent = not failure_type # we consider that a recipient error is a failure with mass mailling and show them as failed for mail in self: if mail.mailing_id: - if mail_sent is True and mail.statistics_ids: - mail.statistics_ids.write({'sent': fields.Datetime.now(), 'exception': False}) - elif mail_sent is False and mail.statistics_ids: - mail.statistics_ids.write({'exception': fields.Datetime.now()}) - return super(MailMail, self)._postprocess_sent_message(success_pids, failure_reason=failure_reason, failure_type=failure_type) + if mail_sent is True and mail.mailing_trace_ids: + mail.mailing_trace_ids.write({'sent': fields.Datetime.now(), 'exception': False}) + elif mail_sent is False and mail.mailing_trace_ids: + mail.mailing_trace_ids.write({'exception': fields.Datetime.now()}) + return super(MailMail, self)._postprocess_sent_message(success_pids, failure_reason=failure_reason, failure_type=failure_type) |
