Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
13390 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer

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

Beste antwoord

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
Annuleer
Auteur

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

Gerelateerde posts Antwoorden Weergaven Activiteit
3
mei 25
2463
0
dec. 23
2312
1
jul. 23
2279
1
sep. 22
2951
0
jul. 22
1861