Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5553 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you Sudhir Arya It's working :)

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 4 20
6633
1
thg 11 20
6558
1
thg 4 24
1201
1
thg 4 20
4341
1
thg 8 24
1486