From 8b3d929a7cae089ac12d9752d3f97793dbe084d5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 12 Jan 2023 11:02:57 +0700 Subject: add new product rest api --- indoteknik_api/controllers/api_v1/product.py | 25 ++++++++++++++++++++++++- indoteknik_custom/models/x_manufactures.py | 2 ++ indoteknik_custom/views/x_manufactures.xml | 16 ++++++++++++++-- 3 files changed, 40 insertions(+), 3 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(): diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py index 1d215cf8..e6842797 100755 --- a/indoteknik_custom/models/x_manufactures.py +++ b/indoteknik_custom/models/x_manufactures.py @@ -42,6 +42,8 @@ class XManufactures(models.Model): ('reset', 'Reset'), ('done', 'Done') ], string="Cache Reset") + sequence = fields.Integer(string='Sequence', help='Urutan tampil di homepage jika show as new product') + show_as_new_product = fields.Boolean(string='Show as New Product', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') def cache_reset(self): manufactures = self.env['x_manufactures'].search([ diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index d122c6c1..c7cedd9c 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -16,13 +16,14 @@ x_manufactures - + + @@ -42,6 +43,8 @@ + + @@ -54,7 +57,16 @@ - + + + + + + + + + + -- cgit v1.2.3