# -*- 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 DashboardController(http.Controller): @http.route('/dashboard-widgets', auth='user', methods=['GET', 'POST']) def getWidgetList(self, **kw): return make_gzip_response({ 'widgets': hp.get_widget_list(), }) @http.route('/dashboard-StockValuation', auth='user', methods=['GET', 'POST']) def getStockValuation(self, **kw): return make_gzip_response({ 'valuation': hp.get_stock_valuation(), 'company': hp.get_company_info(), }) @http.route('/dashboard-StockValuationWithVariantCostPrice', auth='user', methods=['GET', 'POST']) def getStockValuationWithVariantCostPrice(self, **kw): return make_gzip_response({ 'valuation': hp.get_stock_valuation_with_variant_cost_price(), 'company': hp.get_company_info(), }) @http.route('/dashboard-SalePurchaseExpense', auth='user', methods=['GET', 'POST']) def getSalePurchaseExpense(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'modules': hp.get_ir_module_widget(), 'objetives':hp.get_dashboard_objetive_widget(), 'orders':hp.get_pos_order_widget(), 'invoices':hp.get_account_invoice_widget(), 'payslips': hp.get_hr_payslip_widget(), 'voucher': hp.get_account_voucher_widget(), }) @http.route('/dashboard-Balance', auth='user', methods=['GET', 'POST']) def getBalance(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'orders':hp.get_pos_order_widget(), 'invoices':hp.get_account_invoice_widget(), 'payslips': hp.get_hr_payslip_widget(), }) @http.route('/dashboard-IncomeOutcome', auth='user', methods=['GET', 'POST']) def getIncomeOutcome(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'journals':hp.get_payments_journals_widget(), 'vouchers':hp.get_account_voucher_widget(), 'statement_lines':hp.get_account_bank_statement_line_widget(), }) @http.route('/dashboard-Account', auth='user', methods=['GET', 'POST']) def getAccount(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'move_lines': hp.get_account_move_line_widget(), 'vouchers':hp.get_account_voucher_multi_store_widget(), 'reconcile_partials':hp.get_account_move_line_partial_reconcile(), }) @http.route('/dashboard-BankCash', auth='user', methods=['GET', 'POST']) def getBankCash(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'statements': hp.get_account_bank_statement_widget(), }) @http.route('/dashboard-RankingCustomer', auth='user', methods=['GET', 'POST']) def getRankingCustomer(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'partners': hp.get_customer_info(), 'orders':hp.get_pos_order_widget(), 'invoices':hp.get_account_invoice_widget(), }) @http.route('/dashboard-RankingSalesman', auth='user', methods=['GET', 'POST']) def getRankingSalesman(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'users': hp.get_user_info(), 'orders':hp.get_pos_order_widget(), 'invoices':hp.get_account_invoice_widget(), }) @http.route('/dashboard-RankingSaleByStore', auth='user', methods=['GET', 'POST']) def getRankingSaleByStore(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'users': hp.get_user_info(), 'orders':hp.get_pos_order_multi_store_widget(), 'invoices':hp.get_account_invoice_multi_store_widget(), 'stores':hp.get_res_store_widget(), }) @http.route('/dashboard-FinancialState', auth='user', methods=['GET', 'POST']) def getFinancialState(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'invoice_lines': hp.get_account_invoice_line_widget(), 'order_lines': hp.get_pos_order_line_widget(), 'payslips': hp.get_hr_payslip_widget(), }) @http.route('/dashboard-rrhh', auth='user', methods=['GET', 'POST']) def getRRHH(self, **kw): return make_gzip_response({ 'company': hp.get_company_info(), 'payslips': hp.get_hr_payslip_widget(), 'modules': hp.get_ir_module_widget(), # 'orders':hp.get_pos_order_multi_store_widget(), # 'invoices':hp.get_account_invoice_multi_store_widget(), # 'stores':hp.get_res_store_widget(), })