summaryrefslogtreecommitdiff
path: root/indoteknik_custom/controllers/api_controller.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-09-24 13:13:23 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-09-24 13:13:23 +0700
commitd057901e1b30dc24978ec345e4daec1d16abf117 (patch)
treeb049b832447031bb198f3dcb35f4420028568f37 /indoteknik_custom/controllers/api_controller.py
parent66f43a6152ccd63a1d2e2e1f80b0c3825bf39e7f (diff)
Rest API Odoo
Diffstat (limited to 'indoteknik_custom/controllers/api_controller.py')
-rw-r--r--indoteknik_custom/controllers/api_controller.py32
1 files changed, 32 insertions, 0 deletions
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)