I have a custom reports, which needs to be added as an attachment, no matter if Save as Attachment is set or not.
Here is code, I generate PDF with:
pdf = self.env['report'].sudo().get_pdf([invoice.id], 'account.report_invoice')
Here is how I try to create an attachment:.
self.env['ir.attachment'].create({
'name': 'Cats',
'type': 'binary',
'datas': pdf,
'mimetype': 'application/x-pdf'
})
It creates new attachment, but instead of expected PDF, there is just some binary file which could not be recognized into actual PDF. So is there a way to generate real PDF as attachment?