summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-11-21 10:51:58 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-11-21 10:51:58 +0700
commitf0733737bf1f48431da411e3c093f60a2ed75cd7 (patch)
tree405ea9ab0ada9d4aee2403a6b09e20f78194c402
parentb7d183eabc6f3dbf1750191a852c23eb5cb9c5b8 (diff)
product with detail solr
-rw-r--r--indoteknik_api/controllers/api_v1/product.py4
-rw-r--r--indoteknik_api/models/product_template.py19
2 files changed, 15 insertions, 8 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 09ea459d..2e978679 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -101,7 +101,7 @@ class Product(controller.Controller):
product_templates = request.env['product.template'].search(query, limit=limit, offset=offset)
data = {
'product_total': request.env['product.template'].search_count(query),
- 'products': [request.env['product.template'].api_single_response(x, with_detail=True) for x in product_templates]
+ 'products': [request.env['product.template'].api_single_response(x, with_detail='SOLR') for x in product_templates]
}
return self.response(data)
@@ -118,7 +118,7 @@ class Product(controller.Controller):
id = [int(x) for x in id.split(',')]
product_templates = request.env['product.template'].search([('id', 'in', id)])
if product_templates:
- data = [request.env['product.template'].api_single_response(x, with_detail=True) for x in product_templates]
+ data = [request.env['product.template'].api_single_response(x, with_detail='DEFAULT') for x in product_templates]
return self.response(data)
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index e140b326..780c92e5 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -4,7 +4,7 @@ from odoo import models
class ProductTemplate(models.Model):
_inherit = 'product.template'
- def api_single_response(self, product_template, with_detail=False):
+ def api_single_response(self, product_template, with_detail=''):
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id')
product_pricelist_default_discount_id = int(product_pricelist_default_discount_id)
@@ -20,7 +20,17 @@ class ProductTemplate(models.Model):
'manufacture': self.api_manufacture(product_template),
'categories': self.api_categories(product_template),
}
- if with_detail:
+
+ if with_detail != '':
+ data_with_detail = {
+ 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '',
+ 'display_name': product_template.display_name,
+ 'variants': [self.env['product.product'].api_single_response(variant) for variant in product_template.product_variant_ids],
+ 'description': product_template.website_description or '',
+ }
+ data.update(data_with_detail)
+
+ if with_detail == 'SOLR':
rate = 0
if data['lowest_price']['price'] > 0:
rate += 1
@@ -33,12 +43,9 @@ class ProductTemplate(models.Model):
if product_template.qty_stock_vendor > 0:
rate += 1
data_with_detail = {
- 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '',
- 'display_name': product_template.display_name,
- 'variants': [self.env['product.product'].api_single_response(variant) for variant in product_template.product_variant_ids],
- 'description': product_template.website_description or '',
'solr_flag': product_template.solr_flag,
'product_rating': rate,
+ 'search_rank': product_template.search_rank
}
data.update(data_with_detail)
return data