İçereği Atla
Menü
Bu soru işaretlendi
3695 Görünümler

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'}
            )
Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Kas 24
994
0
Oca 23
2271
0
Haz 20
2605
2
Kas 24
952
1
Eyl 24
1411