Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
9110 Weergaven

Hi,

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

Thanks

Avatar
Annuleer
Auteur Beste antwoord

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"
})
Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
7
aug. 20
6985
0
feb. 19
3112
1
nov. 19
3037
0
apr. 19
3122
1
mrt. 19
5871