summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-10-24 15:54:27 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-10-24 15:54:27 +0700
commita069927b8f9b2b5942dffc241ed8b79f2d57ecf8 (patch)
treec465c665e93b76cf938c1eef76a76ef9be664f8c
parent3270307c573ca7a8970899dcc7ee02aa7260a6cb (diff)
Filter price_from and price_to di product Rest API
-rw-r--r--indoteknik_api/controllers/api_v1/blog.py1
-rw-r--r--indoteknik_api/controllers/api_v1/product.py8
-rw-r--r--indoteknik_api/models/product_template.py8
3 files changed, 12 insertions, 5 deletions
diff --git a/indoteknik_api/controllers/api_v1/blog.py b/indoteknik_api/controllers/api_v1/blog.py
index 8d38e4f7..af7c4245 100644
--- a/indoteknik_api/controllers/api_v1/blog.py
+++ b/indoteknik_api/controllers/api_v1/blog.py
@@ -11,7 +11,6 @@ class Blog(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')
limit = int(kw.get('limit', 0))
offset = int(kw.get('offset', 0))
query = [('active', '=', True)]
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 0d5d89b6..d667c1b6 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -40,6 +40,14 @@ class Product(controller.Controller):
if categories:
query.append(('public_categ_ids', 'child_of', [int(x) for x in categories.split(',')]))
+
+ price_from = kw.get('price_from')
+ if price_from and int(price_from):
+ query.append(('web_price_sorting', '>=', int(price_from)))
+
+ price_to = kw.get('price_to')
+ if price_to and int(price_to):
+ query.append(('web_price_sorting', '<=', int(price_to)))
product_variants = request.env['product.product'].search(query)
product_variant_ids = [x.id for x in product_variants]
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index 477be2f3..e99b2c2d 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -1,4 +1,4 @@
-from odoo import models, fields
+from odoo import models
class ProductTemplate(models.Model):
@@ -21,13 +21,13 @@ class ProductTemplate(models.Model):
'categories': self.api_categories(product_template),
}
if with_detail:
- detail_data = {
+ data_with_detail = {
'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 '',
}
for variant in product_template.product_variant_ids:
- detail_data['variants'].append({
+ data_with_detail['variants'].append({
'id': variant.id,
'code': variant.default_code or '',
'name': variant.display_name,
@@ -36,7 +36,7 @@ class ProductTemplate(models.Model):
'weight': variant.weight,
'attributes': [x.name for x in variant.product_template_attribute_value_ids]
})
- data.update(detail_data)
+ data.update(data_with_detail)
return data
def api_manufacture(self, product_template):