main.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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-inmobiliaria', auth='user', methods=['GET', 'POST'])
  26. def getFilterData(self, **kw):
  27. return make_gzip_response({
  28. 'companies': hp.get_res_company_inmobiliaria(),
  29. 'logo': hp.get_company_logo_inmobiliaria(),
  30. 'stores': hp.get_res_store_inmobiliaria(),
  31. 'journals': hp.get_account_journal_inmobiliaria(),
  32. 'users': hp.get_res_users_inmobiliaria(),
  33. 'partner':hp.get_res_partner_inmobiliaria(),
  34. 'supplier':hp.get_supplier_inmobiliaria(),
  35. 'property_state': hp.get_property_state_inmobiliaria(),
  36. })
  37. # CONTRATOS
  38. @http.route('/report-contracts-inmobiliaria', auth='user', methods=['GET', 'POST'])
  39. def getContracts(self, **kw):
  40. return make_gzip_response({
  41. 'contracts': hp.get_contracts_inmobiliaria(),
  42. 'partners': hp.get_res_partner_inmobiliaria(),
  43. })
  44. #COMISIONES
  45. @http.route('/report-sale-history-inmobiliaria', auth='user', methods=['GET', 'POST'])
  46. def getSaleHistory(self, **kw):
  47. return make_gzip_response({
  48. 'invoices': hp.get_account_invoice_sale_type_inmobiliaria(),
  49. 'invoice_line': hp.get_account_invoice_line_out_invoice_inmobiliaria(),
  50. 'orders': hp.get_pos_order_inmobiliaria(),
  51. 'partners': hp.get_all_res_partner_inmobiliaria(),
  52. })
  53. #PROPIEDADES
  54. @http.route('/report-propiedades-inmobiliaria', auth='user', methods=['GET', 'POST'])
  55. def getProductTemplate(self, **kw):
  56. return make_gzip_response({
  57. 'template': hp.get_product_template_inmobiliaria(),
  58. 'supplier':hp.get_supplier_inmobiliaria(),
  59. })
  60. #VENTAS MENSUAL
  61. @http.route('/report-sale-inmobiliaria', auth='user', methods=['GET', 'POST'])
  62. def getSale(self, **kw):
  63. return make_gzip_response({
  64. 'invoices': hp.get_account_invoice_sale_type_inmobiliaria2(),
  65. 'invoice_line': hp.get_account_invoice_line_out_invoice_inmobiliaria(),
  66. 'orders': hp.get_pos_order_inmobiliaria(),
  67. 'partners': hp.get_res_partner_inmobiliaria(),
  68. 'contracts': hp.get_contracts_inmobiliaria(),
  69. 'contract_line': hp.get_contract_line_inmobiliaria(),
  70. })