def incomes(request): wealth = request.session['wealth'] try: date_from, date_to = _validate_dates(request) except ValueError: return rc.BAD_REQUEST report_values = get_incomes(wealth, date_from, date_to) return get_json_response(report_values, total=len(report_values))
def categories(request, category_type): wealth = request.session['wealth'] try: date_from, date_to = _validate_dates(request, True) except ValueError: return rc.BAD_REQUEST if category_type == 'income': split_type = Transaction.TYPE_DEPOSIT else: split_type = Transaction.TYPE_WITHDRAWAL report_values = get_category_breakdown( wealth, split_type, date_from, date_to) return get_json_response(report_values, total=len(report_values))
def netincome(request): wealth = request.session['wealth'] try: date_from, date_to = _validate_dates(request) except ValueError: return rc.BAD_REQUEST expenses = get_expenses(wealth, date_from, date_to) incomes = get_incomes(wealth, date_from, date_to) report_values = [] for i in range(len(incomes)): report_values.append({ 'month': incomes[i]['month'], 'amount': round(incomes[i]['amount'] - float(expenses[i]['amount']), 2)}) return get_json_response(report_values, total=len(report_values))
def index(request): currencies = Currency.objects.all().order_by('symbol') return get_json_response(currencies, _json_currency_handler)