summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v2/product.py
blob: 19a97dec5cde10d1543170acebc3a1ade7148c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from .. import controller
from odoo import http
from odoo.http import request

class V2Product(controller.Controller):
    prefix = '/api/v2/'

    @http.route(prefix + 'product/<id>', auth='public', methods=['GET', 'OPTIONS'])
    @controller.Controller.must_authorized()
    def v2_get_product_by_id(self, **kw):
        id = kw.get('id')
        if not id:
            return self.response(code=400, description='id is required')
        
        data = []
        id = [int(x) for x in id.split(',')]
        product_templates = request.env['product.template'].search([('id', 'in', id)])
        if product_templates:
            data = [request.env['product.template'].v2_api_single_response(x, with_detail='DEFAULT') for x in product_templates]
        
        return self.response(data)