In this blog we will explain how to create url for pdf file in odoo
for an example : we want to generate url for the pdf invoice , so we can create function that takes the invoice id and return the url for the pdf invoice as bellow
from odoo import api , fields, models,SUPERUSER_ID,_
def generate_pdf_invoice_url(self , invoice_id):
# pdf = request.env.ref('module_name.report_action_id').with_user(SUPERUSER_ID)._render_qweb_pdf([invoice_id.id])
pdf = request.env.ref('account.account_invoices').with_user(SUPERUSER_ID)._render_qweb_pdf([invoice_id.id])
pdf_invoice = request.env['ir.attachment'].sudo().create({
'name': invoice_id.name,
'type': 'binary',
'datas': base64.b64encode(pdf[0]),
'store_fname': invoice_id.name,
'res_model': 'account.payment',
'res_id': invoice_id.id,
'mimetype': 'application/x-pdf'
})
pdf_file_url + 'http://'+request.httprequest.__dict__['environ']['HTTP_HOST']+'/web/content/%s' % (pdf_invoice.id)
return pdf_file_url
No comments:
Post a Comment