Ejemplo n.º 1
0
    def test_basic_transfer(self):
        Transfer.do_transfer(self.account1, self.account2, 100)

        self.assertEqual(self.account1.balance, 900)
        self.assertEqual(self.account2.balance, 1100)
        self.assertTrue(Transfer.objects.filter(
            from_account=self.account1,
            to_account=self.account2,
            amount=100,
        ).exists())
Ejemplo n.º 2
0
def execute_scheduled_payments() -> None:
    current_date = timezone.datetime.now().date()
    scheduled_payments = ScheduledPayment.objects.filter(
        next_payment_date=current_date).all()
    for payment in scheduled_payments:
        Transfer.do_transfer(payment.from_account, payment.to_account,
                             payment.amount)
        payment.next_payment_date = add_month(payment.next_payment_date,
                                              payment.original_day)
        payment.save()
Ejemplo n.º 3
0
 def make_transaction(self):
     transfer = Transfer.do_transfer(
         from_account=self.from_account,
         to_account=self.to_account,
         amount=self.amount,
     )
     return transfer
Ejemplo n.º 4
0
def save_transfer(form):
    money = form.cleaned_data['money']
    source = form.cleaned_data['source']
    receiver = form.cleaned_data['receiver']
    Transfer(
        date=form.cleaned_data['date'],
        money=money,
        comment=form.cleaned_data['comment'],
        owner=form.cleaned_data['owner'],
        source=source,
        receiver=receiver,
    ).save()
    change_account(source, receiver, money)
Ejemplo n.º 5
0
 def test_do_transfer_negative_amount(self):
     self.assertRaises(
         ValueError,
         lambda: Transfer.do_transfer(self.account1, self.account2, -1))
Ejemplo n.º 6
0
    def test_zero_or_negative_amount_for_transfer(self):
        with self.assertRaises(NegativeOrZeroAmount):
            Transfer.do_transfer(self.account1, self.account2, 0)

        with self.assertRaises(NegativeOrZeroAmount):
            Transfer.do_transfer(self.account1, self.account2, -10)