Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
9201 Lượt xem

Hi,

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

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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"
})
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
7
thg 8 20
7047
0
thg 2 19
3183
1
thg 11 19
3073
0
thg 4 19
3206
1
thg 3 19
5967