main.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. from openerp import http
  3. from werkzeug.wrappers import Response
  4. from werkzeug.datastructures import Headers
  5. from gzip import GzipFile
  6. from StringIO import StringIO as IO
  7. import simplejson as json
  8. import helpers as hp
  9. import logging
  10. LOGGER = logging.getLogger(__name__)
  11. GZIP_COMPRESSION_LEVEL = 9
  12. def make_gzip_response(data=None, status=200):
  13. gzip_buffer = IO()
  14. with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
  15. gzip_file.write(json.dumps(data))
  16. value = gzip_buffer.getvalue()
  17. gzip_buffer.close()
  18. headers = Headers()
  19. headers.add('Content-Encoding', 'gzip')
  20. headers.add('Vary', 'Accept-Encoding')
  21. headers.add('Content-Length', len(value))
  22. return Response(value, status=status, headers=headers, content_type='application/json')
  23. class ReportController(http.Controller):
  24. # CONSULTA INICIAL
  25. @http.route('/report-filter-data-baco', auth='user', methods=['GET', 'POST'])
  26. def getFilterData(self, **kw):
  27. return make_gzip_response({
  28. 'companies': hp.get_res_company_baco(),
  29. 'logo': hp.get_company_logo_baco(),
  30. 'stores': hp.get_res_store_baco(),
  31. 'journals': hp.get_account_journal_baco(),
  32. 'users': hp.get_res_users_baco(),
  33. 'partner':hp.get_res_partner_baco(),
  34. })
  35. # HISTORICO DE VENTAS
  36. @http.route('/report-sale-history-baco', auth='user', methods=['GET', 'POST'])
  37. def getSaleHistory(self, **kw):
  38. return make_gzip_response({
  39. 'invoices': hp.get_account_invoice_sale_type_baco(),
  40. 'orders': hp.get_pos_order_baco(),
  41. 'partners': hp.get_res_partner_baco(),
  42. })