Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
13202 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar

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

Mejor respuesta

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
Descartar
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

Publicaciones relacionadas Respuestas Vistas Actividad
3
may 25
1974
0
dic 23
1786
1
jul 23
1839
1
sept 22
2545
0
jul 22
1486