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

Hi,

How can we create attachments for the model account.invoice from the other models and from the invoice itself.

Thanks

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

From the account.invoice it self

pdf = self.env.ref('account.account_invoices').sudo().render_qweb_pdf([self.id])[0]
self.env['ir.attachment'].create({
'name': self.number + ".pdf",
'type': 'binary',
'res_id': self.id,
'res_model': 'account.invoice',
'datas': base64.b64encode(pdf),
'mimetype': 'application/x-pdf',
'datas_fname': self.number + ".pdf"
})

From other models

there should be a field in relation with account.invoice, here invoice_id

invoice_id = fields.Many2one('account.invoice')

pdf = self.env.ref('account.account_invoices').sudo().render_qweb_pdf([invoice_id.id])[0]
self.env['ir.attachment'].create({
'name': invoice_id.number + ".pdf",
'type': 'binary',
'res_id': invoice_id.id,
'res_model': 'account.invoice',
'datas': base64.b64encode(pdf),
'mimetype': 'application/x-pdf',
'datas_fname': invoice_id.number + ".pdf"
})
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
7
ส.ค. 20
7369
0
ก.พ. 19
3538
1
พ.ย. 19
3357
0
เม.ย. 19
3604
ir.attachment res_*-fields NULL on save แก้ไขแล้ว
1
มี.ค. 19
6397