Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
5558 Prikazi

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
Opusti
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
Opusti
Avtor

Thank you Sudhir Arya It's working :)

Related Posts Odgovori Prikazi Aktivnost
1
apr. 20
6646
1
nov. 20
6567
1
apr. 24
1205
1
apr. 20
4351
1
avg. 24
1500