Hi,
Please see the answer given for this question: https://www.odoo.com/forum/help-1/question/how-to-print-report-from-website-121485
@http.route('/school/card', methods=['POST', 'GET'], csrf=False, type='http', auth="user", website=True)
def print_id(self, **kw):
student_id = kw['stud_id']
if student_id:
pdf = request.env['report'].sudo().get_pdf([student_id], 'module_name.report_name', data=None)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)
else:
return request.redirect('/')
In Latest version
get_pdf is changed into
render_qweb_pdf. See this sample from
odoo13.
@http.route(['/shop/print'], type='http', auth="public", website=True, sitemap=False)
def print_saleorder(self, **kwargs):
sale_order_id = request.session.get('sale_last_order_id')
if sale_order_id:
pdf, _ = request.env.ref('sale.action_report_saleorder').sudo().render_qweb_pdf([sale_order_id])
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', u'%s' % len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)
else:
return request.redirect('/shop')
Thanks