diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-01-09 10:12:20 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-01-09 10:12:20 +0000 |
| commit | 9eeee43ec3cb57d02a2dcddf03768a2a8f3ea3d8 (patch) | |
| tree | e57fd41c83766b49eb49f871f809ed79add5b5bc /indoteknik_api/controllers/api_v1/district.py | |
| parent | 8a70abf6f05e9ffc6e74ec2e80f61db72f6f0401 (diff) | |
| parent | b1329f940ae66b60185fa097012393b0d51b9e5f (diff) | |
Merged in staging (pull request #16)
Staging
Diffstat (limited to 'indoteknik_api/controllers/api_v1/district.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/district.py | 30 |
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) + |
