From 3d402f5a12d50d2264dde918d4b893b9c8943389 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 2 Feb 2023 17:12:04 +0700 Subject: download tax invoice --- indoteknik_api/controllers/api_v1/download.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 indoteknik_api/controllers/api_v1/download.py (limited to 'indoteknik_api/controllers/api_v1/download.py') diff --git a/indoteknik_api/controllers/api_v1/download.py b/indoteknik_api/controllers/api_v1/download.py new file mode 100644 index 00000000..b215a4cd --- /dev/null +++ b/indoteknik_api/controllers/api_v1/download.py @@ -0,0 +1,25 @@ +from .. import controller +from odoo import http +from odoo.http import request +import base64 + + +class Download(controller.Controller): + PREFIX = '/api/v1/' + + @http.route(PREFIX + 'download/tax-invoice//', auth='none', method=['GET']) + def download_tax_invoice(self, **kw): + id = int(kw.get('id', 0)) + token = kw.get('token', '') + + md5_by_id = request.env['rest.api'].md5_salt(id, 'account.move$') + if md5_by_id == token: + attachment = request.env['ir.attachment'].sudo().search_read([ + ('res_model', '=', 'account.move'), + ('res_field', '=', 'efaktur_document'), + ('res_id', '=', id), + ], ['datas', 'mimetype']) + attachment = attachment[0] + return request.make_response(base64.b64decode(attachment['datas']), [('Content-Type', attachment['mimetype'])]) + + return self.response('Tidak diizinkan') -- cgit v1.2.3