summaryrefslogtreecommitdiff
path: root/indoteknik_custom/controllers/api/product.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-09-24 13:13:23 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-09-24 13:13:23 +0700
commitd057901e1b30dc24978ec345e4daec1d16abf117 (patch)
treeb049b832447031bb198f3dcb35f4420028568f37 /indoteknik_custom/controllers/api/product.py
parent66f43a6152ccd63a1d2e2e1f80b0c3825bf39e7f (diff)
Rest API Odoo
Diffstat (limited to 'indoteknik_custom/controllers/api/product.py')
-rw-r--r--indoteknik_custom/controllers/api/product.py27
1 files changed, 27 insertions, 0 deletions
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)