From f960f1c092cdb7669152f8caca7afad314a59877 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 16 Jan 2023 17:00:16 +0700 Subject: change logic api new product --- indoteknik_api/controllers/api_v1/product.py | 39 +++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 28a63ed5..2e8e0226 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -1,6 +1,7 @@ from .. import controller from odoo import http from odoo.http import request +from datetime import datetime, timedelta import ast @@ -12,20 +13,44 @@ class Product(controller.Controller): if not self.authenticate(): return self.response(code=401, description='Unauthorized') 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') + 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), + ('create_date', '>=', delta_time), + ] + new_products = request.env['product.template'].search(query_products, order='name', limit=500) + 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), + count += 1 + if count == 11: + break + query = [ + ('type', '=', 'product'), + ('active', '=', True), ('x_manufacture', '=', brand.id), + ('image_128', '!=', False), + ('website_description', '!=', False), + ('create_date', '>=', delta_time), ] - products = request.env['product.template'].search(query_products, order='name') + products = request.env['product.template'].search(query, order='name', limit=36) 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': [request.env['product.template'].api_single_response(x) for x in products] }) return self.response(data) -- cgit v1.2.3 From 379389bb98d2980ed583a564a3d7d0754e63ad52 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 09:25:23 +0700 Subject: update api new product --- indoteknik_api/controllers/api_v1/product.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 2e8e0226..bf3505e4 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -3,6 +3,9 @@ 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): @@ -33,7 +36,6 @@ class Product(controller.Controller): data = [] count = 0 for brand in brands: - count += 1 if count == 11: break query = [ @@ -44,15 +46,21 @@ class Product(controller.Controller): ('website_description', '!=', False), ('create_date', '>=', delta_time), ] - products = request.env['product.template'].search(query, order='name', limit=36) + count_products = request.env['product.template'].search_count(query) + if count_products < 5: + _logger.info('Brand Skipped %s' % brand.x_name) + continue + products = request.env['product.template'].search(query, order='name', limit=6) 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 '', + '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']) -- cgit v1.2.3 From 27f620c8b98cd2689f46b4c2f2f19c1c1424aa43 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 09:41:35 +0700 Subject: add param for brand only in new product segment --- indoteknik_api/controllers/api_v1/product.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index bf3505e4..264c3443 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -12,9 +12,12 @@ 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') current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -27,7 +30,7 @@ class Product(controller.Controller): ('website_description', '!=', False), ('create_date', '>=', delta_time), ] - new_products = request.env['product.template'].search(query_products, order='name', limit=500) + new_products = request.env['product.template'].search(query_products, order='create_date', limit=250) brands = [] for product in new_products: brands.append(product.x_manufacture) @@ -36,6 +39,16 @@ class Product(controller.Controller): data = [] count = 0 for brand in brands: + 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 = [ @@ -50,7 +63,7 @@ class Product(controller.Controller): if count_products < 5: _logger.info('Brand Skipped %s' % brand.x_name) continue - products = request.env['product.template'].search(query, order='name', limit=6) + products = request.env['product.template'].search(query, order='name', limit=12) data.append({ 'manufacture_id': brand.id, 'sequence': brand.sequence if brand.sequence else count, -- cgit v1.2.3 From 8f844b005d70dfb473730274ca980a84ae3eb9d7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 09:48:35 +0700 Subject: change min product to 6 in new product api --- indoteknik_api/controllers/api_v1/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 264c3443..ba02b624 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -60,7 +60,7 @@ class Product(controller.Controller): ('create_date', '>=', delta_time), ] count_products = request.env['product.template'].search_count(query) - if count_products < 5: + if count_products < 6: _logger.info('Brand Skipped %s' % brand.x_name) continue products = request.env['product.template'].search(query, order='name', limit=12) -- cgit v1.2.3 From b9724e5d77c702c7418673bac3c711a60e1309d0 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 10:26:21 +0700 Subject: remove filter by date in new product --- indoteknik_api/controllers/api_v1/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index ba02b624..7e86bafd 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -28,7 +28,7 @@ class Product(controller.Controller): ('active', '=', True), ('image_128', '!=', False), ('website_description', '!=', False), - ('create_date', '>=', delta_time), + # ('create_date', '>=', delta_time), ] new_products = request.env['product.template'].search(query_products, order='create_date', limit=250) brands = [] @@ -57,7 +57,7 @@ class Product(controller.Controller): ('x_manufacture', '=', brand.id), ('image_128', '!=', False), ('website_description', '!=', False), - ('create_date', '>=', delta_time), + # ('create_date', '>=', delta_time), ] count_products = request.env['product.template'].search_count(query) if count_products < 6: -- cgit v1.2.3 From f77362c452e04c67927d4572a29157922932d6c7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 10:31:02 +0700 Subject: descending new product --- indoteknik_api/controllers/api_v1/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 7e86bafd..fc8e2610 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -30,7 +30,7 @@ class Product(controller.Controller): ('website_description', '!=', False), # ('create_date', '>=', delta_time), ] - new_products = request.env['product.template'].search(query_products, order='create_date', limit=250) + new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250) brands = [] for product in new_products: brands.append(product.x_manufacture) @@ -63,7 +63,7 @@ class Product(controller.Controller): if count_products < 6: _logger.info('Brand Skipped %s' % brand.x_name) continue - products = request.env['product.template'].search(query, order='name', limit=12) + products = request.env['product.template'].search(query, order='create_date desc', limit=12) data.append({ 'manufacture_id': brand.id, 'sequence': brand.sequence if brand.sequence else count, -- cgit v1.2.3 From 65929f7a9c00639a7b1c360ebc9870b221aa5339 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 08:22:29 +0700 Subject: remove useless code, add last seen products, add compile product in user activity log --- indoteknik_api/controllers/api_v1/customer.py | 38 +++++++++++++++++++++++++++ indoteknik_api/controllers/api_v1/product.py | 6 ++--- 2 files changed, 41 insertions(+), 3 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') 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 fc8e2610..78b03203 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -19,10 +19,10 @@ 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') - current_time = datetime.now() - delta_time = current_time - timedelta(days=30) + # current_time = datetime.now() + # delta_time = current_time - timedelta(days=30) - delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') query_products = [ ('type', '=', 'product'), ('active', '=', True), -- cgit v1.2.3 From f5eecb48f361dd0bc45c2d8b4cf12f34aea5f243 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 13:49:11 +0700 Subject: add brand image in category homepage api --- indoteknik_api/controllers/api_v1/category.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') 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) -- cgit v1.2.3 From b33103dea998552d110d029d7f50ed08f58ce192 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 15:57:33 +0700 Subject: add payment term validation in sales order and add website ads --- indoteknik_api/controllers/api_v1/content.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'indoteknik_api/controllers/api_v1') 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(): -- cgit v1.2.3 From 064a4c0462e68edf89eadee6b5bc7c6508fe30eb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 19 Jan 2023 10:59:33 +0700 Subject: new product must have manufacture id (brand) --- indoteknik_api/controllers/api_v1/product.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 78b03203..cfa2dbef 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -28,6 +28,8 @@ 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) @@ -57,6 +59,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) -- cgit v1.2.3 From 4bc68435bc20d7da0f38bd2370057481cb995584 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 23 Jan 2023 10:52:49 +0700 Subject: add dynamic limit for new product --- indoteknik_api/controllers/api_v1/product.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index cfa2dbef..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) @@ -32,7 +34,7 @@ class Product(controller.Controller): ('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) -- cgit v1.2.3