Skip to content
Snippets Groups Projects
Commit de0951eb authored by Thibault Delavallée's avatar Thibault Delavallée
Browse files

[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
parent fb19bd69
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment