콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5360 화면

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










아바타
취소
작성자 베스트 답변


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

pdf = r.sudo().render_qweb_pdf([int(id)])[0]
아바타
취소
관련 게시물 답글 화면 활동
4
6월 24
1452
Wrong PDF Format 해결 완료
2
3월 24
1846
0
11월 22
2210
2
9월 22
5173
0
1월 21
2199