diff options
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/banner.py | 31 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 14 |
3 files changed, 42 insertions, 4 deletions
diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py index 275313ff..c8280c9a 100644 --- a/indoteknik_api/controllers/api_v1/__init__.py +++ b/indoteknik_api/controllers/api_v1/__init__.py @@ -1,3 +1,4 @@ +from . import banner from . import blog from . import category from . import flash_sale diff --git a/indoteknik_api/controllers/api_v1/banner.py b/indoteknik_api/controllers/api_v1/banner.py new file mode 100644 index 00000000..60f9be85 --- /dev/null +++ b/indoteknik_api/controllers/api_v1/banner.py @@ -0,0 +1,31 @@ +from .. import controller +from odoo import http +from odoo.http import request + + +class Banner(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'banner', auth='public', methods=['GET']) + def get_banner(self, **kw): + if not self.authenticate(): + return self.response(code=401, description='Unauthorized') + + base_url = request.env['ir.config_parameter'].get_param('web.base.url') + type = kw.get('type') + if not type: + return self.response(code=400, description='type is required') + + data = [] + banner_category = request.env['x_banner.category'].search([('x_studio_field_KKVl4', '=', type)], limit=1) + + if banner_category: + for banner in banner_category.banner_ids: + if banner.x_status_banner == 'tayang': + data.append({ + 'name': banner.x_name, + 'url': banner.x_url_banner, + 'image': base_url + 'api/image/x_banner.banner/x_banner_image/' + str(banner.id) if banner.x_banner_image else '', + }) + + return self.response(data)
\ No newline at end of file diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 15f75d98..904670e7 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -15,15 +15,16 @@ class Product(controller.Controller): manufactures = kw.get('manufactures') categories = kw.get('categories') ready_stock = kw.get('ready_stock') + solr_flag = kw.get('solr_flag') - require_betweens = ['name', 'manufactures', 'categories', 'ready_stock'] + require_betweens = ['name', 'manufactures', 'categories', 'ready_stock', 'solr_flag'] is_fulfill = False for required in require_betweens: if kw.get(required): is_fulfill = True if not is_fulfill: - return self.response(code=400, description='name or manufactures or categories is required') + return self.response(code=400, description='name or manufactures or categories or ready_stock or solr_flag is required') query = [('sale_ok', '=', True)] @@ -44,6 +45,11 @@ class Product(controller.Controller): if ready_stock == '1': query.append(('virtual_qty', '>', 0)) + if solr_flag: + query.append(('solr_flag', '=', int(solr_flag))) + + is_with_detail = True if kw.get('with_detail') == '1' else False + price_from = kw.get('price_from') if price_from and int(price_from): query.append(('web_price_sorting', '>=', int(price_from))) @@ -63,7 +69,7 @@ class Product(controller.Controller): product_templates = request.env['product.template'].search(query, limit=limit, offset=offset, order=order) data = { 'product_total': request.env['product.template'].search_count(query), - 'products': [request.env['product.template'].api_single_response(x) for x in product_templates] + 'products': [request.env['product.template'].api_single_response(x, with_detail=is_with_detail) for x in product_templates] } return self.response(data) @@ -84,7 +90,7 @@ class Product(controller.Controller): return self.response(data) - @http.route(prefix + 'product/<id>/similar', auth='public', methods=['GET'], cors="*") + @http.route(prefix + 'product/<id>/similar', auth='public', methods=['GET', 'OPTIONS']) def get_product_similar_by_id(self, **kw): if not self.authenticate(): return self.response(code=401, description='Unauthorized') |
