From d057901e1b30dc24978ec345e4daec1d16abf117 Mon Sep 17 00:00:00 2001 From: IT Fixcomart Date: Sat, 24 Sep 2022 13:13:23 +0700 Subject: Rest API Odoo --- indoteknik_custom/controllers/api_controller.py | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 indoteknik_custom/controllers/api_controller.py (limited to 'indoteknik_custom/controllers/api_controller.py') diff --git a/indoteknik_custom/controllers/api_controller.py b/indoteknik_custom/controllers/api_controller.py new file mode 100644 index 00000000..cb5fae60 --- /dev/null +++ b/indoteknik_custom/controllers/api_controller.py @@ -0,0 +1,32 @@ +import datetime + +from odoo import http +from odoo.http import request +import json +from pytz import timezone + + +class ApiController(http.Controller): + def authenticate(self, kw): + db = kw.get('db') + username = kw.get('username') + password = kw.get('password') + request.session.authenticate(db, username, password) + + def time_to_str(self, object, format): + time = '' + if isinstance(object, datetime.datetime): + time = object.astimezone(timezone('Asia/Jakarta')).strftime(format) + return time + + + def search_with_api_params(self, model: str, kw, default_domain=[]): + limit = kw.get('limit', 0) + offset = kw.get('offset', 0) + order = kw.get('order', '') + domain = kw.get('domain', []) + if domain: + domain = json.loads(domain) + domain += default_domain + + return request.env[model].search(domain, limit=int(limit), offset=int(offset), order=order) -- cgit v1.2.3