Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
4100 มุมมอง

Hello Guys!!!

I am trying to create a pdf file in the table ir_attachment to get attached in an email.

The problem is that the file is created and attached and when i try to dwonload it to check i got an error saying that the file could'nt be open.

Here is what i have tried :

        pdf  = self.env.ref('module.report_pdf').sudo().render_any_docs([quotation_id])[0]

        ATTACHMENT_NAME = "Devis"

        test = pdf.encode('utf-8')

        datas = base64.b64encode(test)

        attachment = self.env['ir.attachment'].create({

            'name': ATTACHMENT_NAME,

            'type': 'binary',

            'datas': datas,

            'datas_fname': ATTACHMENT_NAME + '.pdf',

            'store_fname': ATTACHMENT_NAME,

            'res_model': self._name,

            'res_id': self.ids[0],

        })

Need Help please.
Thanks a lot in advance.
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello @Rihene


The main issue might be in creating pdf file. So please first try to save pdf file in your local pc. If there is no issue in opening an  pdf file in your local PC, then create attachment of that particular pdf.

Can you please mark this as resolved, if you are satisfied with my answer.


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ส.ค. 19
1870
2
พ.ย. 24
675
0
ก.ย. 20
37
0
ส.ค. 20
3488
1
ก.ย. 19
8412