main.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. # HISTORICO DE GASTOS
  25. @http.route('/report-expense-history', auth='user', methods=['GET', 'POST'])
  26. def getExpenseHistory(self, **kw):
  27. return make_gzip_response({
  28. 'invoices': hp.get_account_invoice_expense(),
  29. 'vouchers': hp.get_account_voucher_supplier(),
  30. })
  31. # ANALISIS DE GASTOS
  32. @http.route('/report-expense-analytic', auth='user', methods=['GET', 'POST'])
  33. def getExpenseAnalytic(self, **kw):
  34. return make_gzip_response({
  35. 'invoice_lines': hp.get_account_invoice_line_expense(),
  36. })