diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-01-10 10:09:18 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-01-10 10:09:18 +0700 |
| commit | e4abbde470d917d04256c9804b80d82194d73b51 (patch) | |
| tree | 5f3ec2b28c7197d339b58d13a93967fa4a498a53 /indoteknik_api/controllers/api_v1/sub_district.py | |
| parent | f0f31234dfaa22850ebb502211a4488b4981f17c (diff) | |
| parent | 9eeee43ec3cb57d02a2dcddf03768a2a8f3ea3d8 (diff) | |
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
Diffstat (limited to 'indoteknik_api/controllers/api_v1/sub_district.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sub_district.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/sub_district.py b/indoteknik_api/controllers/api_v1/sub_district.py new file mode 100644 index 00000000..706cc660 --- /dev/null +++ b/indoteknik_api/controllers/api_v1/sub_district.py @@ -0,0 +1,30 @@ +from .. import controller +from odoo import http +from odoo.http import request + +class SubDistrict(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'sub_district', auth='public', methods=['GET', 'OPTIONS']) + def get_sub_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)) + + district_id = kw.get('district_id') + if district_id: + parameters.append(('kecamatan_id', '=', int(district_id))) + + sub_districts = request.env['vit.kelurahan'].search(parameters) + data = [] + for sub_district in sub_districts: + data.append({ 'id': sub_district.id, 'name': sub_district.name }) + + return self.response(data) + |
