summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-12 11:02:57 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-12 11:02:57 +0700
commit8b3d929a7cae089ac12d9752d3f97793dbe084d5 (patch)
tree236f442c309560222940f15b7b6a42e05f6d2b80 /indoteknik_api/controllers/api_v1
parent19bbd3203d41d9f52206d7ceaa96480a19566197 (diff)
add new product rest api
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/product.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 2e978679..28a63ed5 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -6,7 +6,30 @@ import ast
class Product(controller.Controller):
prefix = '/api/v1/'
-
+
+ @http.route(prefix + 'new_product', auth='public', methods=['GET', 'OPTIONS'])
+ def get_new_product(self):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+ base_url = request.env['ir.config_parameter'].get_param('web.base.url')
+ query = [('show_as_new_product', '=', True)]
+ brands = request.env['x_manufactures'].search(query, order='sequence')
+ data = []
+ for brand in brands:
+ query_products = [
+ ('is_new_product', '=', True),
+ ('x_manufacture', '=', brand.id),
+ ]
+ products = request.env['product.template'].search(query_products, order='name')
+ data.append({
+ 'manufacture_id': brand.id,
+ 'sequence': brand.sequence,
+ 'name': brand.x_name,
+ 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(brand.id) if brand.x_logo_manufacture else '',
+ 'products': [request.env['product.template'].api_single_response(x) for x in products]
+ })
+ return self.response(data)
+
@http.route(prefix + 'product', auth='public', methods=['GET', 'OPTIONS'])
def get_product(self, **kw):
if not self.authenticate():