[REF] calendar: clean strange email send code

Purpose: clean mail.mail creation code and use standard mail creation or
template send_mail method.

In calendar there was strange code creating an email based on a template
then updating some values on its mail.message record created through
inherits. It seems simpler to correctly set some specific email arguments
to MailTemplate.send_mail() method and avoid this kind of code construction.

Related task ID 1965040
PR #32459
This commit is contained in:
Thibault Delavallée
2019-04-05 14:05:31 +00:00
parent 742effec8d
commit e7905b820d
+14 -14
View File
@@ -192,27 +192,27 @@ class Attendee(models.Model):
invitation_template = invitation_template.with_context(rendering_context)
# send email with attachments
mails_to_send = self.env['mail.mail']
mail_ids = []
for attendee in self:
if attendee.email or attendee.partner_id.email:
# FIXME: is ics_file text or bytes?
ics_file = ics_files.get(attendee.event_id.id)
mail_id = invitation_template.send_mail(attendee.id, notif_layout='mail.mail_notification_light')
vals = {}
email_values = {
'model': None, # We don't want to have the mail in the tchatter while in queue!
'res_id': None,
}
if ics_file:
vals['attachment_ids'] = [(0, 0, {'name': 'invitation.ics',
'mimetype': 'text/calendar',
'datas_fname': 'invitation.ics',
'datas': base64.b64encode(ics_file)})]
vals['model'] = None # We don't want to have the mail in the tchatter while in queue!
vals['res_id'] = False
current_mail = self.env['mail.mail'].browse(mail_id)
current_mail.mail_message_id.write(vals)
mails_to_send |= current_mail
email_values['attachment_ids'] = [
(0, 0, {'name': 'invitation.ics',
'mimetype': 'text/calendar',
'datas_fname': 'invitation.ics',
'datas': base64.b64encode(ics_file)})
]
mail_ids.append(invitation_template.send_mail(attendee.id, email_values=email_values, notif_layout='mail.mail_notification_light'))
if force_send and mails_to_send:
res = mails_to_send.send()
if force_send and mail_ids:
res = self.env['mail.mail'].browse(mail_ids).send()
return res