diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-01-24 11:43:52 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-01-24 11:43:52 +0700 |
| commit | 2a3a0a7e88ef24456eeda070a7d74f1457efdb18 (patch) | |
| tree | 2bb4cd374d46b5d5e4fb6e32fe239c5ccc83daf4 /indoteknik_api/controllers/api_v1 | |
| parent | 287cf8497b4b6bb825870ee2b3d1b49d4c29ab6a (diff) | |
| parent | 646b9e22fc11f6f1d1b556761a3df2df61f8f59b (diff) | |
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/content.py | 31 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 8 |
2 files changed, 38 insertions, 1 deletions
diff --git a/indoteknik_api/controllers/api_v1/content.py b/indoteknik_api/controllers/api_v1/content.py index 3d4e443a..32828244 100644 --- a/indoteknik_api/controllers/api_v1/content.py +++ b/indoteknik_api/controllers/api_v1/content.py @@ -6,6 +6,37 @@ from odoo.http import request class WebsiteContent(controller.Controller): prefix = '/api/v1/' + @http.route(prefix + 'banner', auth='public', methods=['GET', 'OPTIONS']) + 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') + + category_id = int(kw.get('category_id'), 0) + query = [ + ('x_status_banner', '=', 'tayang'), + ] + + if category_id > 0: + query = [ + ('x_status_banner', '=', 'tayang'), + ('x_banner_category', '=', category_id), + ] + + data = [] + banners = request.env['x_banner.banner'].search(query) + for banner in banners: + data.append({ + # 'image': base_url + 'api/image/x_banner.banner/image' + str(banner.id) if banner.x_banner_image else '', + 'banner_image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id), + 'category_id': banner.x_banner_category.id, + 'category_image': banner.x_banner_category.x_name, + 'name': banner.x_name, + 'url': banner.x_url_banner, + 'status': banner.x_status_banner, + }) + return self.response(data) + @http.route(prefix + 'product_ads', auth='public', methods=['GET', 'OPTIONS']) def get_product_ads(self, **kw): if not self.authenticate(): diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 78b03203..23dcf48e 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -19,6 +19,8 @@ class Product(controller.Controller): is_brand_only = int(kw.get('is_brand_only', 0)) base_url = request.env['ir.config_parameter'].get_param('web.base.url') + limit_new_products = request.env['ir.config_parameter'].get_param('limit.new.product') + limit_new_products = int(limit_new_products) # current_time = datetime.now() # delta_time = current_time - timedelta(days=30) @@ -28,9 +30,11 @@ class Product(controller.Controller): ('active', '=', True), ('image_128', '!=', False), ('website_description', '!=', False), + # ('write_uid', '!=', 1), + ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] - new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250) + new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=limit_new_products) brands = [] for product in new_products: brands.append(product.x_manufacture) @@ -57,6 +61,8 @@ class Product(controller.Controller): ('x_manufacture', '=', brand.id), ('image_128', '!=', False), ('website_description', '!=', False), + # ('write_uid', '!=', 1), + ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] count_products = request.env['product.template'].search_count(query) |
