from .. import controller from odoo import http from odoo.http import request class Voucher(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'voucher', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized() def get_vouchers(self, **kw): code = kw.get('code') visibility = ['public'] parameter = [] if code: visibility.append('private') parameter += [('code', '=', code)] parameter += [('visibility', 'in', visibility)] vouchers = request.env['voucher'].get_active_voucher(parameter) data = vouchers.res_format() return self.response(data)