blob: fce2edf043d55c8fb9d9a41c835c2e989a7b9e84 (
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
28
29
30
31
32
33
34
|
from .. import controller
from odoo import http
from odoo.http import request
class ProductVariant(controller.Controller):
prefix = '/api/v1/'
@http.route(prefix + 'product_variant/<id>', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
def get_product_variant_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_products = request.env['product.product'].search([('id', 'in', id)])
if product_products:
data = [request.env['product.product'].api_single_response(x) for x in product_products]
return self.response(data)
@http.route(prefix + 'product-variant/<product_id>/promotions', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
def get_product_variant_promotions(self, product_id):
product_id = int(product_id)
user_data = self.verify_user_token()
program_line = request.env['promotion.program.line']
program_lines = program_line.get_active_promotions(product_id)
program_lines = program_lines.formats(user=user_data)
return self.response(program_lines)
|