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']) @controller.Controller.must_authorized() def get_sub_district(self, **kw): 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)