Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
9812 Zobrazení

Hi,

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

Thanks

Avatar
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
7
srp 20
7487
0
úno 19
3649
1
lis 19
3439
0
dub 19
3731
1
bře 19
6539