Example #1
0
    def get(self, request, *args, **kwargs):
        now = datetime.now()
        # 全データ
        all_data = Data.get_all_data()
        # 現在銀行
        banks = BankBalance.get_all()
        # クレカ確認日
        credit_checked_date = CreditCheckedDate.get_all()
        today = date.today()
        for c in credit_checked_date:
            # 日付が過ぎていたらpriceを0にする
            if c.date <= today:
                c.price = 0

        # 銀行残高
        all_bank_data = Data.get_bank_data(all_data)
        checked_bank_data = Data.get_checked_data(all_bank_data)
        bank_written = Data.get_income_sum(
            checked_bank_data) - Data.get_outgo_sum(checked_bank_data)

        context = {
            'year': now.year,
            'banks': banks,
            'credit_checked_date': credit_checked_date,
            'bank_written': bank_written,
        }
        return render(request, "_several_checked_date.html", context)
Example #2
0
    def post(self, request, *args, **kwargs):
        written_bank_data = Data.get_checked_data(
            Data.get_bank_data(Data.get_all_data()))
        bank_sum = 0
        bb = BankBalance.get_all()
        cc = CreditCheckedDate.get_all()

        # フォーマットチェック
        try:
            for b in bb:
                key = "bank-" + str(b.pk)
                if key in request.POST:
                    int(request.POST.get(key))

            for c in cc:
                key = "credit-" + str(c.pk)
                if key in request.POST:
                    int(request.POST.get(key))
        except ValueError:
            return HttpResponseBadRequest(
                json.dumps({"message": "invalid parameter"}))

        # 更新と計算
        for b in bb:
            key = "bank-" + str(b.pk)
            if key in request.POST:
                value = int(request.POST.get(key))
                BankBalance.set(b.pk, value)
            bank_sum += BankBalance.get_price(b.pk)

        for c in cc:
            key = "credit-" + str(c.pk)
            if key in request.POST:
                value = int(request.POST.get(key))
                CreditCheckedDate.set_price(c.pk, value)
            bank_sum -= CreditCheckedDate.get_price(c.pk)
        return HttpResponse(
            json.dumps({
                "balance":
                Data.get_income_sum(written_bank_data) -
                Data.get_outgo_sum(written_bank_data) - bank_sum
            }))
Example #3
0
 def test_set(self):
     BankBalance.set(2, 10001)
     data = BankBalance.get_all()
     self.assertEqual(data[0].name, "三井住友")
     self.assertEqual(data[0].price, 10001)
Example #4
0
 def test_get_all(self):
     data = BankBalance.get_all()
     self.assertEqual(data[0].name, "三井住友")
     self.assertEqual(data[0].price, 20000)
     self.assertEqual(data[1].name, "みずほ")
     self.assertEqual(data[1].price, 40000)