تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3681 أدوات العرض

hello can i view my pdf file from odoo while im access it from other application using controller (hitting API endpoint)? right now im only able to download it.. thanks


here are my code to download it:

@http.route('/web/aflowz_attachments/download_all_document/<model_name>/<int:res_id>'type='http'auth="public")
    def download_document(selfmodel_name=Noneres_id=0, **kw):
        attachment_ids = request.env['ir.attachment'].search([('res_model''=', model_name), ('res_id''=', res_id)])
        file_dict = {}
        if attachment_ids:
            for attachment_id in attachment_ids:
                file_store = attachment_id.store_fname
                if file_store:
                    file_name = attachment_id.name
                    file_path = attachment_id._full_path(file_store)
                    file_dict["%s:%s" % (file_store, file_name)] = dict(path=file_path, name=file_name)
            zip_filename = datetime.now()
            zip_filename = "%s.zip" % zip_filename
            bitIO = BytesIO()
            zip_file = zipfile.ZipFile(bitIO, "w", zipfile.ZIP_DEFLATED)
            for file_info in file_dict.values():
                zip_file.write(file_info["path"], file_info["name"])
            zip_file.close()
            return request.make_response(bitIO.getvalue(),
                                        headers=[('Content-Type''application/x-zip-compressed'),
                                                ('Content-Disposition', content_disposition(zip_filename))])
        else:
            return request.make_response(json.dumps({
                "error""Attachments not found",
                "message""There are no attachment",
                "code"404}),
                headers={'Content-Type''application/json'}
            )
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
Error PDF Odoo API تم الحل
1
نوفمبر 24
966
0
يناير 23
2260
0
يونيو 20
2588
2
نوفمبر 24
946
1
سبتمبر 24
1382