跳至内容
菜单
此问题已终结
1 回复
5823 查看

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
7034
1
11月 20
6826
1
4月 24
1421
1
4月 20
4609
1
8月 24
1942