Hello,
I've a binary field in my model. I've attached to this
field a pdf by upload. If I click on the link, I can download the pdf
and read it in a pdf viewer. If I change my field to the widget
pdf_viewer, I can see the pdf directly in my view.
But when I want to attach this pdf to a mail template, the PDF can't be read after receiving the email.
This is my code :
registreds = self.env['x_training_registred'].search([('x_registred_ids', '=', record.x_name)])
for registred in registreds:
template_obj = self.env['mail.template'].browse(77)
attach_obj = self.env['ir.attachment']
attachment_ids = []
#result_rfq_quote = base64.b64decode(record.x_studio_training_plan)
if record.x_studio_training_plan:
attach_data = {
'name': record.x_studio_training_plan_filename,
'datas': record.x_studio_training_plan,
'datas_fname': record.x_studio_training_plan_filename,
'type': 'binary',
'mimetype': 'application/x-pdf'
}
attach_id = attach_obj.create(attach_data)
attachment_ids.append(attach_id.id)
if attachment_ids:
template_obj.write({'attachment_ids': [(6, 0, attachment_ids)]})
If I use b64decode, my pdf size is 0 ko. If I insert the field without decoding the file size is 3ko. The real size is 34ko.
What's wrong with my code ?
Thanks for your help.