summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-17 09:41:35 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-17 09:41:35 +0700
commit27f620c8b98cd2689f46b4c2f2f19c1c1424aa43 (patch)
tree16bf87e77598e8dbf1159780271ffaf25d1ebcf3 /indoteknik_api/controllers/api_v1
parent1f6dddcff502b37cecaef32f30e34d41157134dc (diff)
add param for brand only in new product segment
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/product.py19
1 files changed, 16 insertions, 3 deletions
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,