12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- # -*- 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):
- # CONSULTA INICIAL
- @http.route('/report-filter-data-baco', auth='user', methods=['GET', 'POST'])
- def getFilterData(self, **kw):
- return make_gzip_response({
- 'companies': hp.get_res_company_baco(),
- 'logo': hp.get_company_logo_baco(),
- 'stores': hp.get_res_store_baco(),
- 'journals': hp.get_account_journal_baco(),
- 'users': hp.get_res_users_baco(),
- 'partner':hp.get_res_partner_baco(),
- })
- # HISTORICO DE VENTAS
- @http.route('/report-sale-history-baco', auth='user', methods=['GET', 'POST'])
- def getSaleHistory(self, **kw):
- return make_gzip_response({
- 'invoices': hp.get_account_invoice_sale_type_baco(),
- 'orders': hp.get_pos_order_baco(),
- 'partners': hp.get_res_partner_baco(),
- })
|