diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-07 09:46:35 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-07 09:46:35 +0700 |
| commit | 54182954f66051f102e683b3cc49cf11db71cf19 (patch) | |
| tree | 5e64a2c0e5ec774c70f857a20556036a28450fc0 /indoteknik_api/models/rest_api.py | |
| parent | 7af09e5b533f76ea12c8b68185c3b904f2aecec9 (diff) | |
| parent | ef2f9fefe4df844f5a676d2a166dcd4dfdaa249b (diff) | |
Merge branch 'staging' into release
Diffstat (limited to 'indoteknik_api/models/rest_api.py')
| -rw-r--r-- | indoteknik_api/models/rest_api.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/indoteknik_api/models/rest_api.py b/indoteknik_api/models/rest_api.py new file mode 100644 index 00000000..65119b52 --- /dev/null +++ b/indoteknik_api/models/rest_api.py @@ -0,0 +1,47 @@ +from odoo import models +from odoo.http import request +import datetime +from pytz import timezone +import hashlib +import base64 + + +class RestApi(models.TransientModel): + _name = 'rest.api' + + def datetime_to_str(self, object, format): + time = '' + if isinstance(object, datetime.datetime): + time = object.astimezone(timezone('Asia/Jakarta')).strftime(format) + return time + + def md5_salt(self, value, salt): + 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 |
