Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5552 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

Thank you Sudhir Arya It's working :)

Post correlati Risposte Visualizzazioni Attività
1
apr 20
6633
1
nov 20
6558
1
apr 24
1201
1
apr 20
4341
1
ago 24
1486