Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5557 Vistas

Hello Community,

I'm trying to create an pdf attachement to be send with emails using base64:

I've tried this code with some adjustment

pdf = self.env.ref('hr_timesheet.timesheet_report).report_action(self)

self.env['ir.attachment'].create({

    'name': 'Cats',

    'type': 'binary',

    'datas': base64.encodestring(pdf),

    'res_model': 'account.invoice',

    'res_id': invoice.id

    'mimetype': 'application/x-pdf'

})

But it get this issue expected bytes-like object, not dict

Avatar
Descartar
Mejor respuesta

Try following code:

report
result, format = self.env.ref('hr_timesheet.timesheet_report).render_qweb_pdf(self.ids)
result = base64.b64encode(result) # Use this in attachment creation in datas field

Reference: Email Template Rendering

Avatar
Descartar
Autor

Thank you Sudhir Arya It's working :)

Publicaciones relacionadas Respuestas Vistas Actividad
1
abr 20
6640
1
nov 20
6566
1
abr 24
1204
1
abr 20
4348
1
ago 24
1498