summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-16 17:00:16 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-16 17:00:16 +0700
commitf960f1c092cdb7669152f8caca7afad314a59877 (patch)
tree69e3fa5c1a5b28da935435440d3eb99ef2a2117c /indoteknik_api/controllers/api_v1
parent83ead9edac739720168d615f6282e3978634e461 (diff)
change logic api new product
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/product.py39
1 files changed, 32 insertions, 7 deletions
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)