summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/district.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-10 10:09:18 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-10 10:09:18 +0700
commite4abbde470d917d04256c9804b80d82194d73b51 (patch)
tree5f3ec2b28c7197d339b58d13a93967fa4a498a53 /indoteknik_api/controllers/api_v1/district.py
parentf0f31234dfaa22850ebb502211a4488b4981f17c (diff)
parent9eeee43ec3cb57d02a2dcddf03768a2a8f3ea3d8 (diff)
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
Diffstat (limited to 'indoteknik_api/controllers/api_v1/district.py')
-rw-r--r--indoteknik_api/controllers/api_v1/district.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/district.py b/indoteknik_api/controllers/api_v1/district.py
new file mode 100644
index 00000000..8240ac3b
--- /dev/null
+++ b/indoteknik_api/controllers/api_v1/district.py
@@ -0,0 +1,30 @@
+from .. import controller
+from odoo import http
+from odoo.http import request
+
+class District(controller.Controller):
+ prefix = '/api/v1/'
+
+ @http.route(prefix + 'district', auth='public', methods=['GET', 'OPTIONS'])
+ def get_district(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+
+ parameters = []
+
+ name = kw.get('name')
+ if name:
+ name = '%' + name.replace(' ', '%') + '%'
+ parameters.append(('name', 'ilike', name))
+
+ city_id = kw.get('city_id')
+ if city_id:
+ parameters.append(('kota_id', '=', int(city_id)))
+
+ districts = request.env['vit.kecamatan'].search(parameters)
+ data = []
+ for district in districts:
+ data.append({ 'id': district.id, 'name': district.name })
+
+ return self.response(data)
+