[FIX] calendar: send attachment with calendar event invitation mail
Issue: ====== Attachment files aren't sent with the event invitation email. Steps to reproduce the issue: ============================= - Add any attachment to the email template : `Calendar: Meeting Invitation` and save it. - Go to website and book an appointment. - Go to Scheduled Actions and run manually email queue manager to send the notification. - The sent email doesn't have the attachement you provided, it has only 1 attachement which is the calendar one. Origin of the issue: ==================== The notification of the event invitation was taking only the calendar as attachment and ignores the template attachemnt. Solution: ========== Now the calendar event invitation email will take into account the attachment of the email_template. opw-3593140 closes odoo/odoo#145628 X-original-commit: 28880c32e62b6e2e6c87c35094da0e20c6c14c21 Signed-off-by: Mahdi Cheikh Rouhou (macr) <macr@odoo.com>
This commit is contained in:
@@ -120,9 +120,9 @@ class Attendee(models.Model):
|
||||
event_id = attendee.event_id.id
|
||||
ics_file = ics_files.get(event_id)
|
||||
|
||||
attachment_ids = None
|
||||
attachment_ids = mail_template.attachment_ids.ids
|
||||
if ics_file:
|
||||
attachment_ids = self.env['ir.attachment'].create({
|
||||
attachment_ids += self.env['ir.attachment'].create({
|
||||
'datas': base64.b64encode(ics_file),
|
||||
'description': 'invitation.ics',
|
||||
'mimetype': 'text/calendar',
|
||||
|
||||
@@ -11,6 +11,7 @@ from odoo.addons.base.tests.common import SavepointCaseWithUserDemo
|
||||
import freezegun
|
||||
import pytz
|
||||
import re
|
||||
import base64
|
||||
|
||||
|
||||
class TestCalendar(SavepointCaseWithUserDemo):
|
||||
@@ -305,6 +306,7 @@ class TestCalendar(SavepointCaseWithUserDemo):
|
||||
Check that mail are sent to the attendees on event creation
|
||||
Check that mail are sent to the added attendees on event edit
|
||||
Check that mail are NOT sent to the attendees when the event date is past
|
||||
Check that mail have extra attachement added by the user
|
||||
"""
|
||||
|
||||
def _test_one_mail_per_attendee(self, partners):
|
||||
@@ -315,6 +317,22 @@ class TestCalendar(SavepointCaseWithUserDemo):
|
||||
])
|
||||
self.assertEqual(len(mail), 1)
|
||||
|
||||
def _test_emails_has_attachment(self, partners):
|
||||
# check that every email has an attachment
|
||||
for partner in partners:
|
||||
mail = self.env['mail.message'].sudo().search([
|
||||
('notified_partner_ids', 'in', partner.id),
|
||||
])
|
||||
extra_attachment = mail.attachment_ids.filtered(lambda attachment: attachment.name == "fileText_attachment.txt")
|
||||
self.assertEqual(len(extra_attachment), 1)
|
||||
|
||||
attachment = self.env['ir.attachment'].create({
|
||||
'datas': base64.b64encode(bytes("Event Attachment", 'utf-8')),
|
||||
'name': 'fileText_attachment.txt',
|
||||
'mimetype': 'text/plain'
|
||||
})
|
||||
self.env.ref('calendar.calendar_template_meeting_invitation').attachment_ids = attachment
|
||||
|
||||
partners = [
|
||||
self.env['res.partner'].create({'name': 'testuser0', 'email': u'bob@example.com'}),
|
||||
self.env['res.partner'].create({'name': 'testuser1', 'email': u'alice@example.com'}),
|
||||
@@ -332,6 +350,7 @@ class TestCalendar(SavepointCaseWithUserDemo):
|
||||
|
||||
# every partner should have 1 mail sent
|
||||
_test_one_mail_per_attendee(self, partners)
|
||||
_test_emails_has_attachment(self, partners)
|
||||
|
||||
# adding more partners to the event
|
||||
partners.extend([
|
||||
|
||||
Reference in New Issue
Block a user