summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-01-23 09:20:18 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-01-23 09:20:18 +0000
commitda5f5134f56b2ccf1c1de16c3f7616ab3719f3ea (patch)
treebc1bcb4fb00f2659be81810d528a9cf2cc6ce20d /indoteknik_api/controllers/api_v1
parente52cf84fd2284330412162b44066f29bd382f590 (diff)
parent8af5ee591aabc2d5d946c0eece93a5caab989975 (diff)
Merged in release (pull request #27)
Release
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/category.py3
-rw-r--r--indoteknik_api/controllers/api_v1/content.py20
-rw-r--r--indoteknik_api/controllers/api_v1/customer.py38
-rw-r--r--indoteknik_api/controllers/api_v1/product.py68
4 files changed, 120 insertions, 9 deletions
diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py
index 36e67e01..62faff85 100644
--- a/indoteknik_api/controllers/api_v1/category.py
+++ b/indoteknik_api/controllers/api_v1/category.py
@@ -35,7 +35,8 @@ class Category(controller.Controller):
'name': category.category_id.name,
'image': base_url + 'api/image/website.categories.homepage/image/' + str(category.id) if category.image else '',
'url': category.url,
- 'brands': [y.x_name for y in brands],
+ # 'brands': [y.x_name for y in brands],
+ 'brands': [request.env['x_manufactures'].api_single_response(y) for y in brands],
'products': [request.env['product.template'].api_single_response(x) for x in products]
})
return self.response(data)
diff --git a/indoteknik_api/controllers/api_v1/content.py b/indoteknik_api/controllers/api_v1/content.py
index 3d5b15e5..3d4e443a 100644
--- a/indoteknik_api/controllers/api_v1/content.py
+++ b/indoteknik_api/controllers/api_v1/content.py
@@ -6,6 +6,26 @@ from odoo.http import request
class WebsiteContent(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'product_ads', auth='public', methods=['GET', 'OPTIONS'])
+ def get_product_ads(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')
+ query = [
+ ('page', '=', 'product'),
+ ('status', '=', 'tayang')
+ ]
+ ads = request.env['website.ads'].search(query, order='sequence')
+ data = []
+ for ad in ads:
+ data.append({
+ 'id': ad.id,
+ 'name': ad.name,
+ 'image': base_url + 'api/image/website.ads/image/' + str(ad.id) if ad.image else '',
+ 'url': ad.url,
+ })
+ return self.response(data)
+
@http.route(prefix + 'video_content', auth='public', methods=['GET', 'OPTIONS'])
def get_video_content(self, **kw):
if not self.authenticate():
diff --git a/indoteknik_api/controllers/api_v1/customer.py b/indoteknik_api/controllers/api_v1/customer.py
index f6d6d40d..57120751 100644
--- a/indoteknik_api/controllers/api_v1/customer.py
+++ b/indoteknik_api/controllers/api_v1/customer.py
@@ -7,6 +7,44 @@ import ast
class CustomerReview(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'last_seen_products', auth='public', methods=['GET', 'OPTIONS'])
+ def get_last_seen_products(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+
+ email = str(kw.get('email', ''))
+ if not email:
+ return self.response(code=401, description='Unauthorized')
+
+ activity_logs = request.env['user.activity.log'].search([
+ ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
+ ('email', '=', email),
+ ], order='create_date desc', limit=5)
+
+ data = []
+ templates = []
+ for activity_log in activity_logs:
+ strip_index = i = 0
+ for c in activity_log.url:
+ if c == '-':
+ strip_index = i
+ i += 1
+ template_id = activity_log.url[strip_index + 1:len(activity_log.url)]
+ if '#' in template_id:
+ continue
+ if any(ch.isalpha() for ch in template_id):
+ continue
+ template = request.env['product.template'].search([('id', '=', template_id)])
+ templates.append(template)
+
+ data.append({
+ 'email': email,
+ 'products': [request.env['product.template'].api_single_response(x) for x in templates]
+ })
+ return self.response(data)
+
+
+
@http.route(prefix + 'customer_review', auth='public', methods=['GET', 'OPTIONS'])
def get_customer_review(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 28a63ed5..23dcf48e 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -1,33 +1,85 @@
from .. import controller
from odoo import http
from odoo.http import request
+from datetime import datetime, timedelta
import ast
+import logging
+
+_logger = logging.getLogger(__name__)
class Product(controller.Controller):
prefix = '/api/v1/'
@http.route(prefix + 'new_product', auth='public', methods=['GET', 'OPTIONS'])
- def get_new_product(self):
+ def get_new_product(self, **kw):
if not self.authenticate():
return self.response(code=401, description='Unauthorized')
+
+ is_brand_only = int(kw.get('is_brand_only', 0))
+
base_url = request.env['ir.config_parameter'].get_param('web.base.url')
- query = [('show_as_new_product', '=', True)]
- brands = request.env['x_manufactures'].search(query, order='sequence')
+ 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)
+
+ # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ query_products = [
+ ('type', '=', 'product'),
+ ('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=limit_new_products)
+ brands = []
+ for product in new_products:
+ brands.append(product.x_manufacture)
+ brands = list(dict.fromkeys(brands))
+
data = []
+ count = 0
for brand in brands:
- query_products = [
- ('is_new_product', '=', True),
+ if is_brand_only == 1:
+ data.append({
+ 'manufacture_id': brand.id,
+ 'sequence': brand.sequence if brand.sequence else count,
+ 'name': brand.x_name,
+ 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
+ brand.id) if brand.x_logo_manufacture else '',
+ })
+ continue
+
+ if count == 11:
+ break
+ query = [
+ ('type', '=', 'product'),
+ ('active', '=', True),
('x_manufacture', '=', brand.id),
+ ('image_128', '!=', False),
+ ('website_description', '!=', False),
+ # ('write_uid', '!=', 1),
+ ('x_manufacture', '!=', False),
+ # ('create_date', '>=', delta_time),
]
- products = request.env['product.template'].search(query_products, order='name')
+ count_products = request.env['product.template'].search_count(query)
+ if count_products < 6:
+ _logger.info('Brand Skipped %s' % brand.x_name)
+ continue
+ products = request.env['product.template'].search(query, order='create_date desc', limit=12)
data.append({
'manufacture_id': brand.id,
- 'sequence': brand.sequence,
+ 'sequence': brand.sequence if brand.sequence else count,
'name': brand.x_name,
- 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(brand.id) if brand.x_logo_manufacture else '',
+ 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
+ brand.id) if brand.x_logo_manufacture else '',
+ 'products_total': count_products,
'products': [request.env['product.template'].api_single_response(x) for x in products]
})
+ count += 1
return self.response(data)
@http.route(prefix + 'product', auth='public', methods=['GET', 'OPTIONS'])