summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-03 10:10:16 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-03 10:10:16 +0700
commit9eb80e0aad8966c42fa721738986737b4040e0e4 (patch)
tree003fc22c5a20df26d31c6a9bf0b1684ca07adb3f
parent37329585403b7c47406234677fd1a844360284ff (diff)
[ADD] feature download invoice
-rw-r--r--indoteknik_api/controllers/api_v1/download.py31
-rw-r--r--indoteknik_api/models/account_move.py2
-rw-r--r--indoteknik_api/models/rest_api.py2
3 files changed, 22 insertions, 13 deletions
diff --git a/indoteknik_api/controllers/api_v1/download.py b/indoteknik_api/controllers/api_v1/download.py
index b215a4cd..36f775b5 100644
--- a/indoteknik_api/controllers/api_v1/download.py
+++ b/indoteknik_api/controllers/api_v1/download.py
@@ -7,19 +7,28 @@ 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):
+ def _get_attachment(self, model, field, id):
+ result = request.env['ir.attachment'].sudo().search_read([
+ ('res_model', '=', model),
+ ('res_field', '=', field),
+ ('res_id', '=', id),
+ ], ['datas', 'mimetype'])
+ return result if len(result) > 0 else None
+
+ @http.route(PREFIX + 'download/invoice/<id>', auth='none', method=['GET'])
+ def download_invoice(self, **kw):
id = int(kw.get('id', 0))
- token = kw.get('token', '')
+ return request.render('account.report_invoice', {'id': id})
+
+ @http.route(PREFIX + 'download/tax-invoice/<id>/<token>', auth='none', method=['GET'])
+ def download_tax_invoice(self, id, token):
+ id = int(id)
- md5_by_id = request.env['rest.api'].md5_salt(id, 'account.move$')
+ 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'])])
+ attachment = self._get_attachment('account.move', 'efaktur_document', id)
+ if attachment:
+ return request.make_response(base64.b64decode(attachment['datas']), [('Content-Type', attachment['mimetype'])])
+ return self.response('Dokumen tidak ditemukan', code=404)
return self.response('Tidak diizinkan')
diff --git a/indoteknik_api/models/account_move.py b/indoteknik_api/models/account_move.py
index 5589b5fc..f77ded16 100644
--- a/indoteknik_api/models/account_move.py
+++ b/indoteknik_api/models/account_move.py
@@ -16,7 +16,7 @@ class AccountMove(models.Model):
'amount_total': account_move.amount_total,
'amount_residual': account_move.amount_residual,
'invoice_date': '',
- 'efaktur_token': self.env['rest.api'].md5_salt(account_move.id, 'account.move$') if account_move.efaktur_document else '',
+ 'efaktur_token': self.env['rest.api'].md5_salt(account_move.id, 'account.move') if account_move.efaktur_document else '',
}
if isinstance(object, datetime.date):
data['invoice_date'] = account_move.invoice_date.strftime('%d/%m/%Y')
diff --git a/indoteknik_api/models/rest_api.py b/indoteknik_api/models/rest_api.py
index 2c54769e..052800b7 100644
--- a/indoteknik_api/models/rest_api.py
+++ b/indoteknik_api/models/rest_api.py
@@ -14,4 +14,4 @@ class RestApi(models.TransientModel):
return time
def md5_salt(self, value, salt):
- return hashlib.md5((salt + str(value)).encode()).hexdigest() \ No newline at end of file
+ return hashlib.md5((salt + '$' + str(value)).encode()).hexdigest() \ No newline at end of file