コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
5917 ビュー

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

アバター
破棄
最善の回答

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

アバター
破棄
著作者

Thank you Sudhir Arya It's working :)

関連投稿 返信 ビュー 活動
1
4月 20
7181
1
11月 20
6919
1
4月 24
1496
1
4月 20
4725
1
8月 24
2011