def test_post_str(self): self.client.force_login(User.objects.create_user(self.username)) self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2000) response = self.client.post(reverse('moneybook:actual_cash'), {'price': 'a'}) self.assertEqual(response.status_code, 400) self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2000)
def test_post_str_price(self): self.client.force_login(User.objects.create_user(self.username)) self.assertEqual(SeveralCosts.get_living_cost_mark(), 1000) response = self.client.post(reverse('moneybook:living_cost_mark'), {'price': 'a'}) self.assertEqual(response.status_code, 400) self.assertEqual(SeveralCosts.get_living_cost_mark(), 1000)
def get(self, request, *args, **kwargs): now = datetime.now() # 実際の現金残高 actual_cash_balance = SeveralCosts.get_actual_cash_balance() # クレカ確認日 credit_checked_date = CreditCheckedDate.get_all() # 生活費目標額 living_cost_mark = SeveralCosts.get_living_cost_mark() context = { 'app_name': settings.APP_NAME, 'username': request.user, 'cash_balance': Data.get_income_sum(Data.get_cash_data(Data.get_all_data())) - Data.get_outgo_sum(Data.get_cash_data(Data.get_all_data())), 'year': now.year, 'month': now.month, 'day': now.day, 'actual_cash_balance': actual_cash_balance, 'credit_checked_date': credit_checked_date, 'living_cost_mark': living_cost_mark, } return render(request, "tools.html", context)
def post(self, request, *args, **kwargs): if "price" not in request.POST: return HttpResponseBadRequest( json.dumps({"message": "missing parameter"})) try: price = int(request.POST.get("price")) except ValueError: return HttpResponseBadRequest( json.dumps({"message": "price must be int"})) SeveralCosts.set_actual_cash_balance(price) return HttpResponse()
def test_post_guest(self): self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2000) response = self.client.post(reverse('moneybook:actual_cash'), {'price': 1200}) self.assertEqual(response.status_code, 403) self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2000)
def test_post_guest(self): self.assertEqual(SeveralCosts.get_living_cost_mark(), 1000) response = self.client.post(reverse('moneybook:living_cost_mark'), {'price': 2000}) self.assertEqual(response.status_code, 403) self.assertEqual(SeveralCosts.get_living_cost_mark(), 1000)
def test_set_actual_cash_balance_nothing(self): SeveralCosts.objects.get(name="ActualCashBalance").delete() SeveralCosts.set_actual_cash_balance(2001) self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2001)
def test_set_actual_cash_balance(self): SeveralCosts.set_actual_cash_balance(2001) self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2001)
def test_get_actual_cash_balance(self): self.assertEqual(SeveralCosts.get_actual_cash_balance(), 2000)
def test_set_living_cost_mark_nothing(self): SeveralCosts.objects.get(name="LivingCostMark").delete() SeveralCosts.set_living_cost_mark(1001) self.assertEqual(SeveralCosts.get_living_cost_mark(), 1001)
def test_set_living_cost_mark(self): SeveralCosts.set_living_cost_mark(1001) self.assertEqual(SeveralCosts.get_living_cost_mark(), 1001)
def test_get_living_cost_mark(self): self.assertEqual(SeveralCosts.get_living_cost_mark(), 1000)
def get(self, request, *args, **kwargs): # validation if "year" in request.GET and "month" in request.GET: year = request.GET.get("year") month = request.GET.get("month") if not is_valid_date(year, month): return HttpResponseBadRequest("parameter error") else: return HttpResponseBadRequest("parameter error") # 全データ all_data = Data.get_all_data() # 今月のデータ monthly_data = Data.get_month_data(int(year), int(month)) # 支払い方法リスト methods = Method.list() # 支払い方法ごとの残高 methods_iob = [] methods_monthly_iob = [] for m in methods: d = Data.get_method_data(all_data, m.pk) methods_iob.append( InOutBalance(m.name, None, None, Data.get_income_sum(d) - Data.get_outgo_sum(d))) i = Data.get_income_sum(Data.get_method_data(monthly_data, m.pk)) o = Data.get_outgo_sum(Data.get_method_data(monthly_data, m.pk)) methods_monthly_iob.append(InOutBalance(m.name, i, o, None)) # 立替と貯金 monthly_temp_and_deposit = Data.get_temp_and_deposit_sum(monthly_data) # 通常データ monthly_normal_data = Data.get_normal_data(monthly_data) # 今月の収入 monthly_income = Data.get_income_sum( monthly_normal_data) - monthly_temp_and_deposit # 今月の支出 monthly_outgo = Data.get_outgo_sum( monthly_normal_data) - monthly_temp_and_deposit # 生活費 living_cost = Data.get_living_cost(monthly_data) # 変動費 variable_cost = Data.get_variable_cost(monthly_data) # 生活費目標額 living_cost_mark = SeveralCosts.get_living_cost_mark() # 内部移動以外 monthly_data_without_inmove = Data.filter_without_intra_move( monthly_data) context = { 'total_balance': Data.get_income_sum(all_data) - Data.get_outgo_sum(all_data), 'methods_iob': methods_iob, 'monthly_income': monthly_income, 'monthly_outgo': monthly_outgo, 'monthly_inout': monthly_income - monthly_outgo, 'living_cost': living_cost, 'variable_cost': variable_cost, 'living_remain': living_cost_mark - living_cost, 'variable_remain': monthly_income - max(SeveralCosts.get_living_cost_mark(), living_cost) - variable_cost, 'monthly_all_income': Data.get_income_sum(monthly_data_without_inmove), 'monthly_all_outgo': Data.get_outgo_sum(monthly_data_without_inmove), 'methods_monthly_iob': methods_monthly_iob, } return render(request, '_balance_statistic_mini.html', context)