Odoo Help

3

0
1 Answer
3
Avatar

The Protagonist Belgium

--The Protagonist--

10328
| 5 2 8
Brussels, Belgium
--The Protagonist--

Odoo Techno Functionalist

​​

The Protagonist Belgium
11/14/19, 8:12 AM

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"
})
Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now