Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3702 Widoki

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'}
            )
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lis 24
999
0
sty 23
2274
0
cze 20
2611
2
lis 24
957
1
wrz 24
1414