From d057901e1b30dc24978ec345e4daec1d16abf117 Mon Sep 17 00:00:00 2001 From: IT Fixcomart Date: Sat, 24 Sep 2022 13:13:23 +0700 Subject: Rest API Odoo --- indoteknik_custom/controllers/api/product.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 indoteknik_custom/controllers/api/product.py (limited to 'indoteknik_custom/controllers/api/product.py') diff --git a/indoteknik_custom/controllers/api/product.py b/indoteknik_custom/controllers/api/product.py new file mode 100644 index 00000000..5c5a6c1a --- /dev/null +++ b/indoteknik_custom/controllers/api/product.py @@ -0,0 +1,27 @@ +from .. import api_controller +from odoo import http +from odoo.http import request +import json + + +class ProductApi(api_controller.ApiController): + @http.route('/api/product/search', auth='public', methods=['GET']) + def search_product(self, **kw): + self.authenticate(kw) + limit = kw.get('limit', 0) + offset = kw.get('offset', 0) + order = kw.get('order', '') + domain = kw.get('domain', []) + if domain: + domain = json.loads(domain) + + product_variants = request.env['product.product'].search(domain) + product_variant_ids = [v['id'] for v in product_variants] + domain = [('product_variant_ids', 'in', product_variant_ids)] + products = request.env['product.template'].search(domain, limit=int(limit), offset=int(offset), order=order) + response = [] + for product in products: + response.append({ + 'name': product.name + }) + return json.dumps(response) -- cgit v1.2.3