Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
12651 Представления

Hello everybody,

I want to create an attachment in event.registration module and pass it to email.template, in order to send a mail.

This is my code

@api.one
def mail_attendees(self, template_id, force_send=False, filter_func=lambda self: True):
for attendee in self.registration_ids.filtered(filter_func):
        
        attachment = self.env['ir.attachment'].create({'name': 'registration.ics',
'datas_fname': 'registration.ics',
'datas': str(file.pdf).encode('base64')})
self.env['mail.template'].browse(template_id).send_mail(attendee.id, force_send=force_send)

How can I pass the attachment to mail template ?

Thank you.

Best regards

Аватар
Отменить
Лучший ответ

 You can add your attachment in "attachment_ids" fields.Check below code for the same :-

@api.one def mail_attendees(self, template_id, force_send=False, filter_func=lambda self: True):

    for attendee in self.registration_ids.filtered(filter_func):

        attachment = self.env['ir.attachment'].create({'name': 'registration.ics',

                                  'datas_fname': 'registration.ics',

                                  'datas': str(file.pdf).encode('base64')})

        template = self.env['mail.template'].browse(template_id)

        # Add Attachment

        template.attachment_ids = [(6,0,[attachment.id])]

        template.send_mail(attendee.id, force_send=force_send)


Thanks,

Аватар
Отменить