Skip to Content
Menu
This question has been flagged
1 Reply
4559 Views

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
Discard
Best Answer

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
Discard
Author

Thank you Sudhir Arya It's working :)

Related Posts Replies Views Activity
1
Apr 20
5512
1
Nov 20
5588
1
Apr 24
413
1
Apr 20
3457
1
Aug 24
274