Skip to Content
Menu
This question has been flagged
2 Replies
12707 Views

My question is, just I need a quick response. I need to download a qweb report from odoo website. Now i can only make that as a pdf preview of browser. so what should I need to add on odoo controller ?

My controller code is,


@http.route(['/cms/report/print'], type='http', auth="public", website=True)
def print_docr(self, **kw):
    cr, uid, context = request.cr, SUPERUSER_ID, request.context
     if 2:
        pdf = request.registry['report'].get_pdf(cr, uid, [2], 'x.cms_html_body', data=None,
                                                 context=context)
        pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]

        return request.make_response(pdf, headers=pdfhttpheaders)
Avatar
Discard
Author Best Answer

HI Guys, I solved the issue by changing my header part like

pdfhttpheaders = [ ('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)), ('Content-Disposition', 'attachment; filename="report.pdf"'), ]

Thanks


Avatar
Discard

Hi Hilar, I also want to make similiar feature now, may you provide the full code how to print pdf from Odoo website, please?

Best Answer

Maybe do you have more details to share about it?


I'm trying to handle a report from Javascript, but the result is always the login page even if the report is accessed from the same browser page. If the browser can manually display the report, the script cannot get it correctly, even with many tries in Odoo 11.


The idea is to get sometime a report in PDF and sometimes in HTML. Do you have ideas on the script to use? The better should be to allow different reports too.

Avatar
Discard
Author

can you paste your attempts

I just created a button who call a Javascript function

<button onclick="myFunction()" name="click_me" string="product_id" class="oe_highlight" />

In the function I'v just set the complete URL of the report. This URL give a result when accessed from the browser but the login page when handled by my simple script (that does nothing for the moment, but should just get the report).

I tried to put a route, with absolutely no certitude, but doens'nt work too

class PrintButton(http.Controller):

@http.route('/report/pdf/product.report_productlabel', type='http', auth='user')

def invoice_print(self, date_start=False, date_stop=False, **kw):

r = request.env['report.product.report_productlabel']

pdf, _ = request.env.ref('product.report_productlabel').render_qweb_pdf(r)

pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]

return request.make_response(pdf, headers=pdfhttpheaders)

PS : Odoo 11

Related Posts Replies Views Activity
0
Dec 23
912
1
Jul 23
926
1
May 23
1020
1
Sep 22
1656
0
Jul 22
783