跳至內容
選單
此問題已被標幟
3679 瀏覽次數

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'}
            )
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
11月 24
965
0
1月 23
2254
0
6月 20
2586
2
11月 24
944
1
9月 24
1378