blob: a6484b4d9d911aa2533db4ba0e4ca8015349a376 (
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 District(controller.Controller):
prefix = '/api/v1/'
@http.route(prefix + 'district', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
def get_district(self, **kw):
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)
|