Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
5750 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

Thank you Sudhir Arya It's working :)

Post Terkait Replies Tampilan Aktivitas
1
Apr 20
6913
1
Nov 20
6770
1
Apr 24
1347
1
Apr 20
4538
1
Agu 24
1762