跳至內容
選單
此問題已被標幟
1 回覆
9130 瀏覽次數

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"
})
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
7
8月 20
7000
0
2月 19
3140
1
11月 19
3047
0
4月 19
3163
1
3月 19
5903