diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-03-29 12:22:14 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-10-23 15:29:41 +0000 |
| commit | de0951eb9186a99284560a21700da987863ab4af (patch) | |
| tree | 58cf98b0311d31ea1ebdcf97171f81bc65ee64c2 /addons | |
| parent | fb19bd6938de9348eaaa35d8d20b617d3dab46c0 (diff) | |
[REF] mail: use create multi on mail.mail
Purpose is to prepare future cleanups and speed improvements. In this commit
we use create multi on mail.mail, allowing to batch their creation when
necessary.
Task ID 1853147
PR #39272
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mail/models/mail_mail.py | 24 | ||||
| -rw-r--r-- | addons/mass_mailing/models/mail_mail.py | 17 |
2 files changed, 25 insertions, 16 deletions
diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 029caf22b01..d554ff8edab 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -59,15 +59,23 @@ class MailMail(models.Model): scheduled_date = fields.Char('Scheduled Send Date', help="If set, the queue manager will send the email after the date. If not set, the email will be send as soon as possible.") - @api.model - def create(self, values): + @api.model_create_multi + def create(self, values_list): # notification field: if not set, set if mail comes from an existing mail.message - if 'notification' not in values and values.get('mail_message_id'): - values['notification'] = True - new_mail = super(MailMail, self).create(values) - if values.get('attachment_ids'): - new_mail.attachment_ids.check(mode='read') - return new_mail + for values in values_list: + if 'notification' not in values and values.get('mail_message_id'): + values['notification'] = True + + new_mails = super(MailMail, self).create(values_list) + + new_mails_w_attach = self + for mail, values in zip(new_mails, values_list): + if values.get('attachment_ids'): + new_mails_w_attach += mail + if new_mails_w_attach: + new_mails_w_attach.mapped('attachment_ids').check(mode='read') + + return new_mails def write(self, vals): res = super(MailMail, self).write(vals) diff --git a/addons/mass_mailing/models/mail_mail.py b/addons/mass_mailing/models/mail_mail.py index 845cd05fdfd..519762f3f4d 100644 --- a/addons/mass_mailing/models/mail_mail.py +++ b/addons/mass_mailing/models/mail_mail.py @@ -16,15 +16,16 @@ class MailMail(models.Model): mailing_id = fields.Many2one('mailing.mailing', string='Mass Mailing') 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 mailing.trace """ + @api.model_create_multi + def create(self, values_list): + """ 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 = super(MailMail, self).create(values) - if values.get('mailing_trace_ids'): - mail_sudo = mail.sudo() - mail_sudo.mailing_trace_ids.write({'message_id': mail_sudo.message_id, 'state': 'outgoing'}) - return mail + mails = super(MailMail, self).create(values_list) + for mail, values in zip(mails, values_list): + if values.get('mailing_trace_ids'): + mail_sudo = mail.sudo() + mail_sudo.mailing_trace_ids.write({'message_id': mail_sudo.message_id, 'state': 'outgoing'}) + return mails def _get_tracking_url(self): base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') |
