main.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. # # HISTORICO DE COMPRAS
  59. # @http.route('/report-purchase-history', auth='user', methods=['GET', 'POST'])
  60. # def getPurchaseHistory(self, **kw):
  61. # return make_gzip_response({
  62. # 'invoices': hp.get_account_invoice_purchase_type(),
  63. # 'vouchers': hp.get_account_voucher_supplier(),
  64. # })
  65. #
  66. # # ANALISIS DE COMPRAS
  67. # @http.route('/report-purchase-analytic', auth='user', methods=['GET', 'POST'])
  68. # def getPurchaseAnalytic(self, **kw):
  69. # return make_gzip_response({
  70. # 'invoice_lines': hp.get_account_invoice_line_in_invoice_purchase(),
  71. # })
  72. # # HISTORICO DE GASTOS
  73. # @http.route('/report-expense-history', auth='user', methods=['GET', 'POST'])
  74. # def getExpenseHistory(self, **kw):
  75. # return make_gzip_response({
  76. # 'invoices': hp.get_account_invoice_expense_type(),
  77. # 'vouchers': hp.get_account_voucher_supplier(),
  78. # })
  79. #
  80. # # ANALISIS DE GASTOS
  81. # @http.route('/report-expense-analytic', auth='user', methods=['GET', 'POST'])
  82. # def getExpenseAnalytic(self, **kw):
  83. # return make_gzip_response({
  84. # 'invoice_lines': hp.get_account_invoice_line_in_invoice_expense(),
  85. # })
  86. # RANKING DE PRODUCTOS
  87. @http.route('/report-sale-product-ranking', auth='user', methods=['GET', 'POST'])
  88. def getSaleProductRanking(self, **kw):
  89. return make_gzip_response({
  90. 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
  91. 'order_lines': hp.get_pos_order_line(),
  92. 'products': hp.get_product_product(),
  93. })
  94. # RANKING DE CLIENTES
  95. @http.route('/report-sale-customer-ranking', auth='user', methods=['GET', 'POST'])
  96. def getSaleCustomerRanking(self, **kw):
  97. return make_gzip_response({
  98. 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
  99. 'order_lines': hp.get_pos_order_line(),
  100. 'partners': hp.get_customers(),
  101. })
  102. # # RESUMEN DE VENTAS
  103. # @http.route('/report-sale-summary', auth='user', methods=['GET', 'POST'])
  104. # def getSaleSummary(self, **kw):
  105. # return make_gzip_response({
  106. # 'invoices': hp.get_account_invoice_sale_and_refund_type(),
  107. # 'orders': hp.get_pos_order(),
  108. # })
  109. #
  110. # # PERDIDAS Y GANANCIAS
  111. # @http.route('/report-profit-loss', auth='user', methods=['GET', 'POST'])
  112. # def getProfitLoss(self, **kw):
  113. # return make_gzip_response({
  114. # 'invoice_lines': hp.get_account_invoice_line_all_type(),
  115. # 'order_lines': hp.get_pos_order_line(),
  116. # 'product_categories': hp.get_product_category_expense(),
  117. # })
  118. #
  119. # # ANALISIS DE UTILIDAD DE VENTAS
  120. # @http.route('/report-sale-utility-analytic', auth='user', methods=['GET', 'POST'])
  121. # def getSaleUtilityAnalytic(self, **kw):
  122. # return make_gzip_response({
  123. # 'invoice_lines': hp.get_account_invoice_line_out_invoice_and_out_refund(),
  124. # 'order_lines': hp.get_pos_order_line(),
  125. # })