summaryrefslogtreecommitdiff
path: root/indoteknik_api/models/rest_api.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-13 10:41:41 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-13 10:41:41 +0700
commitcfa0aa5c242b14332f7bc970bb65f1fbde0a9f3b (patch)
tree91f855964cadb0c76094cd2cc6b51f7994ce0c6d /indoteknik_api/models/rest_api.py
parentfb04f8f3c533740c79c130ab4bc097b8529cae8e (diff)
parent7478616937cff56ccb994138831f90eae904e724 (diff)
fix conflict
Diffstat (limited to 'indoteknik_api/models/rest_api.py')
-rw-r--r--indoteknik_api/models/rest_api.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/indoteknik_api/models/rest_api.py b/indoteknik_api/models/rest_api.py
index 052800b7..65119b52 100644
--- a/indoteknik_api/models/rest_api.py
+++ b/indoteknik_api/models/rest_api.py
@@ -1,7 +1,9 @@
from odoo import models
+from odoo.http import request
import datetime
from pytz import timezone
import hashlib
+import base64
class RestApi(models.TransientModel):
@@ -14,4 +16,32 @@ 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()
+
+ def md5_salt_valid(self, value, salt, token):
+ return hashlib.md5((salt + '$' + str(value)).encode()).hexdigest() == token
+
+ def get_single_attachment(self, model, field, id):
+ domain = [
+ ('res_model', '=', model),
+ ('res_field', '=', field),
+ ('res_id', '=', id),
+ ]
+ fields = ['datas', 'mimetype']
+ result = self.env['ir.attachment'].sudo().search_read(domain, fields)
+ return result[0] if len(result) > 0 else None
+
+ def response_attachment(self, data = {}):
+ decode_content = data.get('decode_content', False)
+ if decode_content:
+ data['content'] = base64.b64decode(data['content'])
+
+ return request.make_response(
+ data['content'],
+ [
+ ('Content-Type', data['mimetype']),
+ ('Content-Disposition', 'attachment; filename=%s' % data['filename']),
+ ('Content-Length', len(data['content']))
+ ]
+ )
+ \ No newline at end of file