Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
14212 มุมมอง

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.


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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 
อวตาร
ละทิ้ง
ผู้เขียน

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.

คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ธ.ค. 24
4897
Expect singleton: res.currency[SOLVED] แก้ไขแล้ว
2
มิ.ย. 23
4714
0
มี.ค. 22
2563
0
ส.ค. 21
5236
0
เม.ย. 18
8735