main.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. 'logo': hp.get_company_logo(),
  30. 'stores': hp.get_res_store(),
  31. 'journals': hp.get_account_journal(),
  32. 'users': hp.get_res_users(),
  33. 'categories': hp.get_product_category_all(),
  34. 'brands': hp.get_product_brand(),
  35. 'attributes': hp.get_product_attribute(),
  36. 'attribute_values': hp.get_product_attribute_value(),
  37. })
  38. # HISTORICO DE VENTAS
  39. @http.route('/report-sale-history', auth='user', methods=['GET', 'POST'])
  40. def getSaleHistory(self, **kw):
  41. return make_gzip_response({
  42. 'invoices': hp.get_account_invoice_sale_type(),
  43. 'orders': hp.get_pos_order(),
  44. 'vouchers': hp.get_account_voucher_customer(),
  45. })
  46. # ANALISIS DE VENTAS
  47. @http.route('/report-sale-analytic', auth='user', methods=['GET', 'POST'])
  48. def getSaleAnalytic(self, **kw):
  49. return make_gzip_response({
  50. 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
  51. 'order_lines': hp.get_pos_order_line(),
  52. })
  53. # HISTORICO DE COMPRAS
  54. @http.route('/report-purchase-history', auth='user', methods=['GET', 'POST'])
  55. def getPurchaseHistory(self, **kw):
  56. return make_gzip_response({
  57. 'invoices': hp.get_account_invoice_purchase_type(),
  58. 'vouchers': hp.get_account_voucher_supplier(),
  59. })
  60. # ANALISIS DE COMPRAS
  61. @http.route('/report-purchase-analytic', auth='user', methods=['GET', 'POST'])
  62. def getPurchaseAnalytic(self, **kw):
  63. return make_gzip_response({
  64. 'invoice_lines': hp.get_account_invoice_line_in_invoice_purchase(),
  65. 'invoices': hp.get_account_invoice_purchase_type(),
  66. })
  67. # HISTORICO DE GASTOS
  68. @http.route('/report-expense-history', auth='user', methods=['GET', 'POST'])
  69. def getExpenseHistory(self, **kw):
  70. return make_gzip_response({
  71. 'invoices': hp.get_account_invoice_expense_type(),
  72. 'vouchers': hp.get_account_voucher_supplier(),
  73. })
  74. # ANALISIS DE GASTOS
  75. @http.route('/report-expense-analytic', auth='user', methods=['GET', 'POST'])
  76. def getExpenseAnalytic(self, **kw):
  77. return make_gzip_response({
  78. 'invoice_lines': hp.get_account_invoice_line_in_invoice_expense(),
  79. 'invoices': hp.get_account_invoice_expense_type(),
  80. })
  81. # RANKING DE PRODUCTOS
  82. @http.route('/report-sale-product-ranking', auth='user', methods=['GET', 'POST'])
  83. def getSaleProductRanking(self, **kw):
  84. return make_gzip_response({
  85. 'invoice_lines': hp.get_account_invoice_line_out_invoice_and_out_refund(),
  86. 'order_lines': hp.get_pos_order_line(),
  87. 'products': hp.get_product_product(),
  88. })
  89. # RANKING DE CLIENTES
  90. @http.route('/report-sale-customer-ranking', auth='user', methods=['GET', 'POST'])
  91. def getSaleCustomerRanking(self, **kw):
  92. return make_gzip_response({
  93. 'invoice_lines': hp.get_account_invoice_line_out_invoice_and_out_refund(),
  94. 'order_lines': hp.get_pos_order_line(),
  95. 'partners': hp.get_res_partner(),
  96. })
  97. # RESUMEN DE VENTAS
  98. @http.route('/report-sale-summary', auth='user', methods=['GET', 'POST'])
  99. def getSaleSummary(self, **kw):
  100. return make_gzip_response({
  101. 'invoices': hp.get_account_invoice_sale_and_refund_type(),
  102. 'orders': hp.get_pos_order(),
  103. })
  104. # PERDIDAS Y GANANCIAS
  105. @http.route('/report-profit-loss', auth='user', methods=['GET', 'POST'])
  106. def getProfitLoss(self, **kw):
  107. return make_gzip_response({
  108. 'invoice_lines': hp.get_account_invoice_line_all_type(),
  109. 'order_lines': hp.get_pos_order_line(),
  110. 'product_categories': hp.get_product_category_expense(),
  111. })
  112. # ANALISIS DE UTILIDAD DE VENTAS
  113. @http.route('/report-sale-utility-analytic', auth='user', methods=['GET', 'POST'])
  114. def getSaleUtilityAnalytic(self, **kw):
  115. return make_gzip_response({
  116. 'invoice_lines': hp.get_account_invoice_line_out_invoice_and_out_refund(),
  117. 'order_lines': hp.get_pos_order_line(),
  118. })
  119. # PAGOS DE CLIENTES
  120. @http.route('/report-account-voucher-customer-payment', auth='user', methods=['GET', 'POST'])
  121. def getCustomerAccountVoucher(self, **kw):
  122. return make_gzip_response({
  123. 'vouchers': hp.get_account_voucher_payment(),
  124. 'statement_lines': hp.get_account_bank_statement_line(),
  125. 'move_lines': hp.get_account_move_line(),
  126. 'invoices': hp.get_account_invoice_sale_type(),
  127. })
  128. # PAGOS A PROVEEDORES
  129. @http.route('/report-supplier-account-voucher', auth='user', methods=['GET', 'POST'])
  130. def getSupplierAccountVoucher(self, **kw):
  131. return make_gzip_response({
  132. 'vouchers': hp.get_account_voucher_supplier(),
  133. 'invoices': hp.get_account_invoice_purchase_type(),
  134. })
  135. # PAGOS DE CLIENTES
  136. @http.route('/report-account-voucherrefund-customer-payment', auth='user', methods=['GET', 'POST'])
  137. def getCustomerAccountRefundVoucher(self, **kw):
  138. return make_gzip_response({
  139. 'vouchers': hp.get_account_voucher_payment(),
  140. 'statement_lines': hp.get_account_bank_statement_line(),
  141. 'move_lines': hp.get_account_move_line(),
  142. 'invoices': hp.get_account_invoice_sale_and_refund_type(),
  143. })
  144. # LIBRO DE VENTAS
  145. @http.route('/report-sale-journal', auth='user', methods=['GET', 'POST'])
  146. def getSaleJournal(self, **kw):
  147. return make_gzip_response({
  148. 'invoices': hp.get_account_invoice_sale_type(),
  149. 'orders': hp.get_pos_order(),
  150. })
  151. # LIBRO DE COMPRAS
  152. @http.route('/report-purchase-journal', auth='user', methods=['GET', 'POST'])
  153. def getPurchaseJournal(self, **kw):
  154. return make_gzip_response({
  155. 'invoice_lines': hp.get_account_invoice_line_in_invoice_expense(),
  156. 'orders': hp.get_account_invoice_expense_type(),
  157. })