summaryrefslogtreecommitdiff
path: root/indoteknik_custom/controllers/api/product.py
blob: 5c5a6c1a6658a2baee00f8653c6afb1f4a30b5ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)