main.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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', auth='user', methods=['GET', 'POST'])
  26. def getFilterData(self, **kw):
  27. return make_gzip_response({
  28. 'companies': hp.get_res_company(),
  29. 'stores': hp.get_res_store(),
  30. 'journals': hp.get_account_journal(),
  31. 'users': hp.get_res_users(),
  32. 'categories': hp.get_product_category_all(),
  33. 'brands': hp.get_product_brand(),
  34. 'attributes': hp.get_product_attribute(),
  35. 'attribute_values': hp.get_product_attribute_value(),
  36. })
  37. # HISTORICO DE VENTAS
  38. @http.route('/report-sale-history', auth='user', methods=['GET', 'POST'])
  39. def getSaleHistory(self, **kw):
  40. return make_gzip_response({
  41. 'invoices': hp.get_account_invoice_sale_type(),
  42. 'orders': hp.get_pos_order(),
  43. 'vouchers': hp.get_account_voucher_customer(),
  44. })
  45. # ANALISIS DE VENTAS
  46. @http.route('/report-sale-analytic', auth='user', methods=['GET', 'POST'])
  47. def getSaleAnalytic(self, **kw):
  48. return make_gzip_response({
  49. 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
  50. 'order_lines': hp.get_pos_order_line(),
  51. })
  52. # CLIENTES
  53. @http.route('/report-customers', auth='user', methods=['GET', 'POST'])
  54. def getCustomers(self, **kw):
  55. return make_gzip_response({
  56. 'customers': hp.get_customers(),
  57. })
  58. # CATALOGO DE PRODUCTOS
  59. @http.route('/report-product-list', auth='user', methods=['GET', 'POST'])
  60. def getCustomers(self, **kw):
  61. return make_gzip_response({
  62. 'products': hp.get_product_product(),
  63. 'currencies': hp.get_res_currency(),
  64. })
  65. # # HISTORICO DE COMPRAS
  66. # @http.route('/report-purchase-history', auth='user', methods=['GET', 'POST'])
  67. # def getPurchaseHistory(self, **kw):
  68. # return make_gzip_response({
  69. # 'invoices': hp.get_account_invoice_purchase_type(),
  70. # 'vouchers': hp.get_account_voucher_supplier(),
  71. # })
  72. #
  73. # # ANALISIS DE COMPRAS
  74. # @http.route('/report-purchase-analytic', auth='user', methods=['GET', 'POST'])
  75. # def getPurchaseAnalytic(self, **kw):
  76. # return make_gzip_response({
  77. # 'invoice_lines': hp.get_account_invoice_line_in_invoice_purchase(),
  78. # })
  79. # # HISTORICO DE GASTOS
  80. # @http.route('/report-expense-history', auth='user', methods=['GET', 'POST'])
  81. # def getExpenseHistory(self, **kw):
  82. # return make_gzip_response({
  83. # 'invoices': hp.get_account_invoice_expense_type(),
  84. # 'vouchers': hp.get_account_voucher_supplier(),
  85. # })
  86. #
  87. # # ANALISIS DE GASTOS
  88. # @http.route('/report-expense-analytic', auth='user', methods=['GET', 'POST'])
  89. # def getExpenseAnalytic(self, **kw):
  90. # return make_gzip_response({
  91. # 'invoice_lines': hp.get_account_invoice_line_in_invoice_expense(),
  92. # })
  93. # RANKING DE PRODUCTOS
  94. @http.route('/report-sale-product-ranking', auth='user', methods=['GET', 'POST'])
  95. def getSaleProductRanking(self, **kw):
  96. return make_gzip_response({
  97. 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
  98. 'order_lines': hp.get_pos_order_line(),
  99. 'products': hp.get_product_product(),
  100. })
  101. # RANKING DE CLIENTES
  102. @http.route('/report-sale-customer-ranking', auth='user', methods=['GET', 'POST'])
  103. def getSaleCustomerRanking(self, **kw):
  104. return make_gzip_response({
  105. 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
  106. 'order_lines': hp.get_pos_order_line(),
  107. 'partners': hp.get_customers(),
  108. })
  109. # # RESUMEN DE VENTAS
  110. # @http.route('/report-sale-summary', auth='user', methods=['GET', 'POST'])
  111. # def getSaleSummary(self, **kw):
  112. # return make_gzip_response({
  113. # 'invoices': hp.get_account_invoice_sale_and_refund_type(),
  114. # 'orders': hp.get_pos_order(),
  115. # })
  116. #
  117. # # PERDIDAS Y GANANCIAS
  118. # @http.route('/report-profit-loss', auth='user', methods=['GET', 'POST'])
  119. # def getProfitLoss(self, **kw):
  120. # return make_gzip_response({
  121. # 'invoice_lines': hp.get_account_invoice_line_all_type(),
  122. # 'order_lines': hp.get_pos_order_line(),
  123. # 'product_categories': hp.get_product_category_expense(),
  124. # })
  125. #
  126. # # ANALISIS DE UTILIDAD DE VENTAS
  127. # @http.route('/report-sale-utility-analytic', auth='user', methods=['GET', 'POST'])
  128. # def getSaleUtilityAnalytic(self, **kw):
  129. # return make_gzip_response({
  130. # 'invoice_lines': hp.get_account_invoice_line_out_invoice_and_out_refund(),
  131. # 'order_lines': hp.get_pos_order_line(),
  132. # })