summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/promotion.py
blob: 14d98b141579c1e32813735e40c50574f52001c6 (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
from .. import controller
from odoo import http
from odoo.http import request
import ast


class Promotion(controller.Controller):
    prefix = '/api/v1/'
    
    @http.route(prefix + 'promotion/<id>', auth='public', methods=['GET'])
    def get_promotion_by_id(self, **kw):
        if not self.authenticate():
            return self.response(code=401, description='Unauthorized')
        
        base_url = request.env['ir.config_parameter'].get_param('web.base.url')
        id = kw.get('id')
        if not id:
            return self.response(code=400, description='id is required')
        
        data = {}
        id = int(id)
        coupon_program = request.env['coupon.program'].search([('id', '=', id)])
        if coupon_program:
            data = {
                'banner': base_url + 'api/image/coupon.program/x_studio_banner_promo/' + str(coupon_program.id) if coupon_program.x_studio_banner_promo else '',
                'image': base_url + 'api/image/coupon.program/x_studio_image_promo/' + str(coupon_program.id) if coupon_program.x_studio_image_promo else '',
                'name': coupon_program.name,
            }
        
        return self.response(data)