summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/promotion.py
blob: b137fe2ec05e0c5e92ef375c9cddea61ebbfcce1 (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
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'])
    @controller.Controller.must_authorized()
    def get_promotion_by_id(self, **kw):
        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)