123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- # -*- coding: utf-8 -*-
- from openerp import http
- from werkzeug.wrappers import Response
- from werkzeug.datastructures import Headers
- from gzip import GzipFile
- from StringIO import StringIO as IO
- import simplejson as json
- import helpers as hp
- import logging
- LOGGER = logging.getLogger(__name__)
- GZIP_COMPRESSION_LEVEL = 9
- def make_gzip_response(data=None, status=200):
- gzip_buffer = IO()
- with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
- gzip_file.write(json.dumps(data))
- value = gzip_buffer.getvalue()
- gzip_buffer.close()
- headers = Headers()
- headers.add('Content-Encoding', 'gzip')
- headers.add('Vary', 'Accept-Encoding')
- headers.add('Content-Length', len(value))
- return Response(value, status=status, headers=headers, content_type='application/json')
- class ReportController(http.Controller):
- # CONSULTA INICIAL
- @http.route('/report-filter-data', auth='user', methods=['GET', 'POST'])
- def getFilterData(self, **kw):
- return make_gzip_response({
- 'companies': hp.get_res_company(),
- 'stores': hp.get_res_store(),
- 'journals': hp.get_account_journal(),
- 'users': hp.get_res_users(),
- 'categories': hp.get_product_category_all(),
- 'brands': hp.get_product_brand(),
- 'attributes': hp.get_product_attribute(),
- 'attribute_values': hp.get_product_attribute_value(),
- })
- # HISTORICO DE VENTAS
- @http.route('/report-sale-history', auth='user', methods=['GET', 'POST'])
- def getSaleHistory(self, **kw):
- return make_gzip_response({
- 'invoices': hp.get_account_invoice_sale_type(),
- 'orders': hp.get_pos_order(),
- 'vouchers': hp.get_account_voucher_customer(),
- })
- # ANALISIS DE VENTAS
- @http.route('/report-sale-analytic', auth='user', methods=['GET', 'POST'])
- def getSaleAnalytic(self, **kw):
- return make_gzip_response({
- 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
- 'order_lines': hp.get_pos_order_line(),
- })
- # CLIENTES
- @http.route('/report-customers', auth='user', methods=['GET', 'POST'])
- def getCustomers(self, **kw):
- return make_gzip_response({
- 'customers': hp.get_customers(),
- })
- # CATALOGO DE PRODUCTOS
- @http.route('/report-product-list', auth='user', methods=['GET', 'POST'])
- def getCustomers(self, **kw):
- return make_gzip_response({
- 'products': hp.get_product_product(),
- 'currencies': hp.get_res_currency(),
- })
- # # HISTORICO DE COMPRAS
- # @http.route('/report-purchase-history', auth='user', methods=['GET', 'POST'])
- # def getPurchaseHistory(self, **kw):
- # return make_gzip_response({
- # 'invoices': hp.get_account_invoice_purchase_type(),
- # 'vouchers': hp.get_account_voucher_supplier(),
- # })
- #
- # # ANALISIS DE COMPRAS
- # @http.route('/report-purchase-analytic', auth='user', methods=['GET', 'POST'])
- # def getPurchaseAnalytic(self, **kw):
- # return make_gzip_response({
- # 'invoice_lines': hp.get_account_invoice_line_in_invoice_purchase(),
- # })
- # # HISTORICO DE GASTOS
- # @http.route('/report-expense-history', auth='user', methods=['GET', 'POST'])
- # def getExpenseHistory(self, **kw):
- # return make_gzip_response({
- # 'invoices': hp.get_account_invoice_expense_type(),
- # 'vouchers': hp.get_account_voucher_supplier(),
- # })
- #
- # # ANALISIS DE GASTOS
- # @http.route('/report-expense-analytic', auth='user', methods=['GET', 'POST'])
- # def getExpenseAnalytic(self, **kw):
- # return make_gzip_response({
- # 'invoice_lines': hp.get_account_invoice_line_in_invoice_expense(),
- # })
- # RANKING DE PRODUCTOS
- @http.route('/report-sale-product-ranking', auth='user', methods=['GET', 'POST'])
- def getSaleProductRanking(self, **kw):
- return make_gzip_response({
- 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
- 'order_lines': hp.get_pos_order_line(),
- 'products': hp.get_product_product(),
- })
- # RANKING DE CLIENTES
- @http.route('/report-sale-customer-ranking', auth='user', methods=['GET', 'POST'])
- def getSaleCustomerRanking(self, **kw):
- return make_gzip_response({
- 'invoice_lines': hp.get_account_invoice_line_out_invoice(),
- 'order_lines': hp.get_pos_order_line(),
- 'partners': hp.get_customers(),
- })
- # # RESUMEN DE VENTAS
- # @http.route('/report-sale-summary', auth='user', methods=['GET', 'POST'])
- # def getSaleSummary(self, **kw):
- # return make_gzip_response({
- # 'invoices': hp.get_account_invoice_sale_and_refund_type(),
- # 'orders': hp.get_pos_order(),
- # })
- #
- # # PERDIDAS Y GANANCIAS
- # @http.route('/report-profit-loss', auth='user', methods=['GET', 'POST'])
- # def getProfitLoss(self, **kw):
- # return make_gzip_response({
- # 'invoice_lines': hp.get_account_invoice_line_all_type(),
- # 'order_lines': hp.get_pos_order_line(),
- # 'product_categories': hp.get_product_category_expense(),
- # })
- #
- # # ANALISIS DE UTILIDAD DE VENTAS
- # @http.route('/report-sale-utility-analytic', auth='user', methods=['GET', 'POST'])
- # def getSaleUtilityAnalytic(self, **kw):
- # return make_gzip_response({
- # 'invoice_lines': hp.get_account_invoice_line_out_invoice_and_out_refund(),
- # 'order_lines': hp.get_pos_order_line(),
- # })
|