Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
14207 Lượt xem

Hello

I want to generate report through API.

E.g.

I I create API like /api/generate_pdf with type="htpp" and method="GET".after accessing this API able to generate report.

I know that how report is created in odoo but I don't have idea from API(controller) report is generated.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Please see the answer given for this question: https://www.odoo.com/forum/help-1/question/how-to-print-report-from-website-121485

@http.route('/school/card', methods=['POST', 'GET'], csrf=False, type='http', auth="user", website=True)
def print_id(self, **kw):
student_id = kw['stud_id']
if student_id:
pdf = request.env['report'].sudo().get_pdf([student_id], 'module_name.report_name', data=None)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)

else:
return request.redirect('/')
In Latest version get_pdf is changed into render_qweb_pdf. See this sample from odoo13.

@http.route(['/shop/print'], type='http', auth="public", website=True, sitemap=False)
def print_saleorder(self, **kwargs):
sale_order_id = request.session.get('sale_last_order_id')
if sale_order_id:
pdf, _ = request.env.ref('sale.action_report_saleorder').sudo().render_qweb_pdf([sale_order_id])
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', u'%s' % len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)

else:
return request.redirect('/shop')
Thanks 
Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks it work but If I want to create report from external application(written in other language) then is it possible to generate report from odoo v12.

Câu trả lời hay nhất

Api to get pdf file preview:

@http.route(['/schedule_pdf'], type='http', auth="public", website=True, sitemap=False)
def schedule_pdf(self, **kw):         
​if kw.get('id'):      
​as_model = request.env['alwathba.schedule'].sudo().browse([int(kw.get('id'))])
​         content = base64.b64decode(str(as_model.pdf_file.decode("utf-8")))     
​pdfhttpheaders = [('Content-Type', 'application/pdf'),('Content-Length', u'%s' % len(content))]      
​return request.make_response(content, headers=pdfhttpheaders)
 



to access pdf: https://yourcompany.com/schedule_pdf?id=14

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 12 24
4894
2
thg 6 23
4713
0
thg 3 22
2563
0
thg 8 21
5235
0
thg 4 18
8728