This question has been flagged
1 Reply
4105 Views

Hi,


I'm trying to generate a report from my controller. It's should act as when I click on the "Print" button in the web client, but the PDF is empty / corrupted.


@http.route('/web/print', type='http', auth="user")
def print_expense(self, id, **kw):
    r = request.env.ref('hr_expense.action_report_hr_expense_sheet')
    pdf = r.sudo().render_qweb_pdf([int(id)])

    pdfhttpheaders = [('Content-Type', 'application/pdf'),
                        ('Content-Length', len(pdf)),]
    return request.make_response(pdf, headers=pdfhttpheaders)

The log output for the manual click and the controller are the same

werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/content/1969-55e1068/web.report_assets_common.css HTTP/1.1" 200 - 5 0.009 0.029
werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/content/350-c65afe6/web.report_assets_pdf.css HTTP/1.1" 200 - 5 0.019 0.029
werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/static/src/fonts/google/Raleway/Raleway-Regular.ttf HTTP/1.1" 200 - - - -
werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/static/src/fonts/lato/Lato-Reg-webfont.woff HTTP/1.1" 200 - - - -
werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/static/src/fonts/lato/Lato-Lig-webfont.woff HTTP/1.1" 200 - - - -
werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/static/src/fonts/lato/Lato-Bol-webfont.woff HTTP/1.1" 200 - - - -
werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/static/src/fonts/lato/Lato-Hai-webfont.woff HTTP/1.1" 200 - - - -
werkzeug: 127.0.0.1 - - [30/Sep/2020 21:28:07] "GET /web/static/src/fonts/lato/Lato-Bla-webfont.woff HTTP/1.1" 200 - - - -
odoo.addons.base.models.ir_actions_report: The PDF report has been generated for model: hr.expense.sheet, records [1].


What am I doing wrong ?


Regards










Avatar
Discard
Author Best Answer


Found a solution. render_qweb_pdf returns two values content and format.

pdf = r.sudo().render_qweb_pdf([int(id)])[0]
Avatar
Discard