main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. # PAGOS DE CLIENTES
  25. @http.route('/report-account-voucherrefund-customer-payment', auth='user', methods=['GET', 'POST'])
  26. def getCustomerAccountRefundVoucher(self, **kw):
  27. return make_gzip_response({
  28. 'vouchers': hp.get_account_voucher_payment(),
  29. 'statement_lines': hp.get_account_bank_statement_line(),
  30. 'move_lines': hp.get_account_move_line(),
  31. 'invoices': hp.get_account_invoice_sale_and_refund_type(),
  32. })