summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/download.py
blob: b215a4cd890e1b2c56f66d746f8627fb699d5620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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/<id>/<token>', 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')