تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
5744 أدوات العرض

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
أبريل 20
6893
1
نوفمبر 20
6758
1
أبريل 24
1338
1
أبريل 20
4522
1
أغسطس 24
1749