main.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. # ANALISIS DE UTILIDAD DE VENTAS
  25. @http.route('/report-sale-finance-analytic', auth='user', methods=['GET', 'POST'])
  26. def getSaleAnalytic(self, **kw):
  27. return make_gzip_response({
  28. 'invoice_lines': hp.get_account_invoice_line_utility(),
  29. 'order_lines': hp.get_pos_order_line_utility(),
  30. })