Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5821 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

Thank you Sudhir Arya It's working :)

Related Posts Răspunsuri Vizualizări Activitate
1
apr. 20
7027
1
nov. 20
6826
1
apr. 24
1418
1
apr. 20
4608
1
aug. 24
1935