summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-11-01 16:44:44 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-11-01 16:44:44 +0700
commit25ab8a7f448c5a7045b6944839622a3f79900164 (patch)
treed9025986a02f3bf7cea2ee34ea4cfaa9f7063556
parent9a7b506816c724a8af10b51622532f773257f203 (diff)
Add filter by solr_flag and with_detail in rest api product search
-rw-r--r--indoteknik_api/controllers/api_v1/product.py12
-rw-r--r--indoteknik_api/models/product_template.py6
2 files changed, 14 insertions, 4 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 26a7f1ec..904670e7 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -15,15 +15,16 @@ class Product(controller.Controller):
manufactures = kw.get('manufactures')
categories = kw.get('categories')
ready_stock = kw.get('ready_stock')
+ solr_flag = kw.get('solr_flag')
- require_betweens = ['name', 'manufactures', 'categories', 'ready_stock']
+ require_betweens = ['name', 'manufactures', 'categories', 'ready_stock', 'solr_flag']
is_fulfill = False
for required in require_betweens:
if kw.get(required):
is_fulfill = True
if not is_fulfill:
- return self.response(code=400, description='name or manufactures or categories is required')
+ return self.response(code=400, description='name or manufactures or categories or ready_stock or solr_flag is required')
query = [('sale_ok', '=', True)]
@@ -44,6 +45,11 @@ class Product(controller.Controller):
if ready_stock == '1':
query.append(('virtual_qty', '>', 0))
+ if solr_flag:
+ query.append(('solr_flag', '=', int(solr_flag)))
+
+ is_with_detail = True if kw.get('with_detail') == '1' else False
+
price_from = kw.get('price_from')
if price_from and int(price_from):
query.append(('web_price_sorting', '>=', int(price_from)))
@@ -63,7 +69,7 @@ class Product(controller.Controller):
product_templates = request.env['product.template'].search(query, limit=limit, offset=offset, order=order)
data = {
'product_total': request.env['product.template'].search_count(query),
- 'products': [request.env['product.template'].api_single_response(x) for x in product_templates]
+ 'products': [request.env['product.template'].api_single_response(x, with_detail=is_with_detail) 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 e99b2c2d..a1e2e5a4 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -25,6 +25,8 @@ class ProductTemplate(models.Model):
'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '',
'variants': [],
'description': product_template.website_description or '',
+ 'solr_flag': product_template.solr_flag,
+ 'product_rating': product_template.product_rating,
}
for variant in product_template.product_variant_ids:
data_with_detail['variants'].append({
@@ -34,7 +36,9 @@ class ProductTemplate(models.Model):
'price': self.env['product.pricelist'].compute_price(product_pricelist_default_discount_id, variant.id),
'stock': variant.qty_stock_vendor,
'weight': variant.weight,
- 'attributes': [x.name for x in variant.product_template_attribute_value_ids]
+ 'attributes': [x.name for x in variant.product_template_attribute_value_ids],
+ 'solr_flag': product_template.solr_flag,
+ 'product_rating': product_template.product_rating,
})
data.update(data_with_detail)
return data