blob: 3af7f2e1c669a261321afb1fe74d4e06c9c1227a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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)
|