Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
13122 Ansichten

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
Verwerfen
Autor Beste Antwort

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
Verwerfen

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 Antwort

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
Verwerfen
Autor

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

Verknüpfte Beiträge Antworten Ansichten Aktivität
3
Mai 25
1782
0
Dez. 23
1559
1
Juli 23
1608
1
Sept. 22
2311
0
Juli 22
1315