Пример #1
0
    def test_total_balance(self):

        bankaccount = BankAccountFactory(balance=0, owners=[self.superowner])

        url = reverse('banktransactions:list', kwargs={
            'bankaccount_pk': bankaccount.pk
        })

        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-15.59',
            date=datetime.date(2015, 6, 3),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-4.41',
            date=datetime.date(2015, 6, 3),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.00',
            date=datetime.date(2015, 6, 3),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.59',
            date=datetime.date(2015, 6, 4),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='6.59',
            date=datetime.date(2015, 6, 4),
        )
        bankaccount.refresh_from_db()
        self.assertEqual(bankaccount.balance, Decimal('-2.82'))

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.total_balance for obj in object_list],
            [
                Decimal('-15.59'),
                Decimal('-20'),
                Decimal('-15'),
                Decimal('-9.41'),
                Decimal('-2.82'),
            ],
        )

        bankaccount.balance_initial = Decimal('150')
        bankaccount.save()

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.total_balance for obj in object_list],
            [
                Decimal('150') + Decimal('-15.59'),
                Decimal('150') + Decimal('-20'),
                Decimal('150') + Decimal('-15'),
                Decimal('150') + Decimal('-9.41'),
                Decimal('150') + Decimal('-2.82'),
            ],
        )
Пример #2
0
    def test_total_balance(self):

        bankaccount = BankAccountFactory(balance=0, owners=[self.superowner])

        url = reverse('banktransactions:list',
                      kwargs={'bankaccount_pk': bankaccount.pk})

        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-15.59',
            date=datetime.date(2015, 6, 3),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-4.41',
            date=datetime.date(2015, 6, 3),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.00',
            date=datetime.date(2015, 6, 3),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.59',
            date=datetime.date(2015, 6, 4),
        )
        BankTransactionFactory(
            bankaccount=bankaccount,
            amount='6.59',
            date=datetime.date(2015, 6, 4),
        )
        bankaccount.refresh_from_db()
        self.assertEqual(bankaccount.balance, Decimal('-2.82'))

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.total_balance for obj in object_list],
            [
                Decimal('-15.59'),
                Decimal('-20'),
                Decimal('-15'),
                Decimal('-9.41'),
                Decimal('-2.82'),
            ],
        )

        bankaccount.balance_initial = Decimal('150')
        bankaccount.save()

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.total_balance for obj in object_list],
            [
                Decimal('150') + Decimal('-15.59'),
                Decimal('150') + Decimal('-20'),
                Decimal('150') + Decimal('-15'),
                Decimal('150') + Decimal('-9.41'),
                Decimal('150') + Decimal('-2.82'),
            ],
        )
Пример #3
0
    def test_reconciled_balance(self):

        bankaccount = BankAccountFactory(balance=0, owners=[self.superowner])

        url = reverse('banktransactions:list', kwargs={
            'bankaccount_pk': bankaccount.pk
        })

        bt1 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-15.59',
            date=datetime.date(2015, 6, 3),
        )
        bt2 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-4.41',
            reconciled=True,
            date=datetime.date(2015, 6, 3),
        )
        bt3 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.00',
            reconciled=True,
            date=datetime.date(2015, 6, 3),
        )
        bt4 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.59',
            date=datetime.date(2015, 6, 4),
        )
        bt5 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='6.59',
            reconciled=True,
            date=datetime.date(2015, 6, 4),
        )

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.pk for obj in object_list],
            [bt1.pk, bt2.pk, bt3.pk, bt4.pk, bt5.pk],
        )

        self.assertListEqual(
            [obj.reconciled_balance for obj in object_list],
            [
                # None, which should be balance initial instead. But this is
                # done in the template to prevent useless queryset loop just
                # for this special use case.
                None,
                Decimal('-4.41'),  # First reconciled bank transaction.
                Decimal('0.59'),  # -4.41 + 5
                Decimal('0.59'),  # Not reconciled, so previous value: 0.59
                Decimal('7.18'),  # 0.59 + 6.59
            ],
        )

        bankaccount.balance_initial = Decimal('150')
        bankaccount.save()

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.reconciled_balance for obj in object_list],
            [
                None,
                Decimal('150') + Decimal('-4.41'),
                Decimal('150') + Decimal('0.59'),
                Decimal('150') + Decimal('0.59'),
                Decimal('150') + Decimal('7.18'),
            ],
        )
Пример #4
0
    def test_reconciled_balance(self):

        bankaccount = BankAccountFactory(balance=0, owners=[self.superowner])

        url = reverse('banktransactions:list',
                      kwargs={'bankaccount_pk': bankaccount.pk})

        bt1 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-15.59',
            date=datetime.date(2015, 6, 3),
        )
        bt2 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='-4.41',
            reconciled=True,
            date=datetime.date(2015, 6, 3),
        )
        bt3 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.00',
            reconciled=True,
            date=datetime.date(2015, 6, 3),
        )
        bt4 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='5.59',
            date=datetime.date(2015, 6, 4),
        )
        bt5 = BankTransactionFactory(
            bankaccount=bankaccount,
            amount='6.59',
            reconciled=True,
            date=datetime.date(2015, 6, 4),
        )

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.pk for obj in object_list],
            [bt1.pk, bt2.pk, bt3.pk, bt4.pk, bt5.pk],
        )

        self.assertListEqual(
            [obj.reconciled_balance for obj in object_list],
            [
                # None, which should be balance initial instead. But this is
                # done in the template to prevent useless queryset loop just
                # for this special use case.
                None,
                Decimal('-4.41'),  # First reconciled bank transaction.
                Decimal('0.59'),  # -4.41 + 5
                Decimal('0.59'),  # Not reconciled, so previous value: 0.59
                Decimal('7.18'),  # 0.59 + 6.59
            ],
        )

        bankaccount.balance_initial = Decimal('150')
        bankaccount.save()

        response = self.app.get(url, user='******')
        object_list = list(reversed(response.context[0].get('object_list')))
        self.assertListEqual(
            [obj.reconciled_balance for obj in object_list],
            [
                None,
                Decimal('150') + Decimal('-4.41'),
                Decimal('150') + Decimal('0.59'),
                Decimal('150') + Decimal('0.59'),
                Decimal('150') + Decimal('7.18'),
            ],
        )