diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-02-10 10:36:16 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-02-10 10:36:16 +0700 |
| commit | bbf176b0ce51ade22b74d0df2023025a4cef3efa (patch) | |
| tree | 24d2d3c7e3fed5c0672a9063a09e3c4d33ba3dac /indoteknik_api/models/rest_api.py | |
| parent | bd01d7a842c8b6e4aea6a2fc3615a9d57fbcd470 (diff) | |
| parent | b0de64ae769148a009d0a08a957c5c35dee174a9 (diff) | |
Merge branch 'release' into line_no_sales_order
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 |
