123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- # -*- 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(),
- 'logo': hp.get_company_logo(),
- '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(),
- })
- # 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(),
- 'invoices': hp.get_account_invoice_purchase_type(),
- })
- # 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(),
- 'invoices': hp.get_account_invoice_expense_type(),
- })
- # 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_and_out_refund(),
- '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_and_out_refund(),
- 'order_lines': hp.get_pos_order_line(),
- 'partners': hp.get_res_partner(),
- })
- # 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(),
- })
- # PAGOS DE CLIENTES
- @http.route('/report-account-voucher-customer-payment', auth='user', methods=['GET', 'POST'])
- def getCustomerAccountVoucher(self, **kw):
- return make_gzip_response({
- 'vouchers': hp.get_account_voucher_payment(),
- 'statement_lines': hp.get_account_bank_statement_line(),
- 'move_lines': hp.get_account_move_line(),
- 'invoices': hp.get_account_invoice_sale_type(),
- })
- # PAGOS A PROVEEDORES
- @http.route('/report-supplier-account-voucher', auth='user', methods=['GET', 'POST'])
- def getSupplierAccountVoucher(self, **kw):
- return make_gzip_response({
- 'vouchers': hp.get_account_voucher_supplier(),
- 'invoices': hp.get_account_invoice_purchase_type(),
- })
- # PAGOS DE CLIENTES
- @http.route('/report-account-voucherrefund-customer-payment', auth='user', methods=['GET', 'POST'])
- def getCustomerAccountRefundVoucher(self, **kw):
- return make_gzip_response({
- 'vouchers': hp.get_account_voucher_payment(),
- 'statement_lines': hp.get_account_bank_statement_line(),
- 'move_lines': hp.get_account_move_line(),
- 'invoices': hp.get_account_invoice_sale_and_refund_type(),
- })
- # LIBRO DE VENTAS
- @http.route('/report-sale-journal', auth='user', methods=['GET', 'POST'])
- def getSaleJournal(self, **kw):
- return make_gzip_response({
- 'invoices': hp.get_account_invoice_sale_type(),
- 'orders': hp.get_pos_order(),
- })
- # LIBRO DE COMPRAS
- @http.route('/report-purchase-journal', auth='user', methods=['GET', 'POST'])
- def getPurchaseJournal(self, **kw):
- return make_gzip_response({
- 'invoice_lines': hp.get_account_invoice_line_in_invoice_expense(),
- 'orders': hp.get_account_invoice_expense_type(),
- })
|