diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-11-01 16:44:44 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-11-01 16:44:44 +0700 |
| commit | 25ab8a7f448c5a7045b6944839622a3f79900164 (patch) | |
| tree | d9025986a02f3bf7cea2ee34ea4cfaa9f7063556 /indoteknik_api/controllers/api_v1 | |
| parent | 9a7b506816c724a8af10b51622532f773257f203 (diff) | |
Add filter by solr_flag and with_detail in rest api product search
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 12 |
1 files changed, 9 insertions, 3 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) |
