# -*- coding: utf-8 -*- from openerp import http from werkzeug.wrappers import Response from werkzeug.datastructures import Headers from gzip import GzipFile from StringIO import StringIO as IO import simplejson as json import helpers as hp import logging LOGGER = logging.getLogger(__name__) GZIP_COMPRESSION_LEVEL = 9 def make_gzip_response(data=None, status=200): gzip_buffer = IO() with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file: gzip_file.write(json.dumps(data)) value = gzip_buffer.getvalue() gzip_buffer.close() headers = Headers() headers.add('Content-Encoding', 'gzip') headers.add('Vary', 'Accept-Encoding') headers.add('Content-Length', len(value)) return Response(value, status=status, headers=headers, content_type='application/json') class ReportController(http.Controller): # HISTORICO DE COMPRAS @http.route('/report-purchase-history', auth='user', methods=['GET', 'POST']) def getPurchaseHistory(self, **kw): return make_gzip_response({ 'invoices': hp.get_account_invoice_purchase(), 'vouchers': hp.get_account_voucher_supplier(), }) # ANALISIS DE COMPRAS @http.route('/report-purchase-analytic', auth='user', methods=['GET', 'POST']) def getPurchaseAnalytic(self, **kw): return make_gzip_response({ 'invoice_lines': hp.get_account_invoice_line_purchase(), })