コード例 #1
0
 def test103_trans_move(self):
     finac.asset_create('UAH')
     finac.asset_set_rate('UAH/USD', value=0.04)
     finac.account_create('move.test', 'usd', 'current', 'Test move acc')
     finac.account_create('move1.TEST', 'UAH', 'current', 'Test move acc2')
     finac.transaction_create('move.test', 100, 'for move test')
     self.assertEqual(finac.account_balance('move.test'), 100)
     target_ct = 80
     target_dt = 1200
     finac.transaction_move('move1.TEST',
                            'move.test',
                            target_ct=target_ct,
                            tag='go ahead',
                            note='cross currency: target_ct')
     self.assertEqual(finac.account_balance('move.test'), target_ct)
     finac.transaction_move('move1.TEST',
                            'move.test',
                            target_dt=target_dt,
                            tag='ahead',
                            note='cross currency: target_dt')
     self.assertEqual(finac.account_balance('move1.test'), target_dt)
     self.assertRaises(ValueError,
                       finac.transaction_move,
                       'move1.TEST',
                       'move.test',
                       target_dt=100)
     print()
     finac.ls('move.test')
     finac.ls('move1.test')
     print()
コード例 #2
0
 def test051_hack_overlimit(self):
     finac.account_create('TEST.HL', 'EUR', max_balance=100)
     t1 = finac.transaction_create('TEST.HL', 100, mark_completed=False)
     try:
         t2 = finac.transaction_create('TEST.HL', 100, mark_completed=False)
         finac.transaction_complete(t1)
         finac.transaction_complete(t2)
         raise RuntimeError('Overlimit hacked')
     except finac.OverlimitError:
         return
コード例 #3
0
 def test050_hack_overdraft(self):
     finac.account_create('TEST.HO', 'EUR', max_overdraft=100)
     tid = finac.transaction_create('TEST.HO', -100, mark_completed=False)
     self.assertEqual(finac.account_balance('TEST.HO'), -100)
     try:
         finac.transaction_create('TEST.HO', -10, mark_completed=False)
         raise RuntimeError('Overdraft hacked')
     except finac.OverdraftError:
         pass
     finac.transaction_complete(tid)
     self.assertEqual(finac.account_balance('TEST.HO'), -100)
コード例 #4
0
 def test042_overdraft_and_delete(self):
     finac.account_create('TEST42.TEST', 'EUR', max_overdraft=100)
     finac.transaction_create('TEST42.TEST', 10)
     tid = finac.transaction_create('TEST42.TEST',
                                    -100,
                                    mark_completed=False)
     finac.transaction_delete(tid)
     tid = finac.transaction_create('TEST42.TEST',
                                    -100,
                                    mark_completed=False)
     finac.transaction_delete(tid)
     self.assertEqual(finac.account_balance('TEST42.TEST'), 10)
コード例 #5
0
 def test003_create_transaction(self):
     result.transaction1_id = finac.transaction_create(
         'test.test',
         100,
         'test',
         'Test balance import',
         mark_completed=False)
     self.assertEqual(finac.account_balance('TEST.TEST'), 0)
     statement = list(
         finac.account_statement('TEST.TEST', '2019-01-01', pending=False))
     self.assertEqual(len(statement), 0)
     statement = list(
         finac.account_statement('test.test', '2019-01-01', pending=True))
     self.assertEqual(len(statement), 1)
コード例 #6
0
    def test040_overdraft(self):

        # allow overdraft
        finac.account_create('TEST3.TEST',
                             'eur',
                             'current',
                             'Test account',
                             max_overdraft=900)
        finac.transaction_create('TEST3.TEST', 100)
        finac.transaction_move('TEST2.TEST', 'TEST3.TEST', '1,000.00')
        self.assertEqual(finac.account_balance('TEST3.TEST'), -900)

        # forbid overdraft
        finac.account_create('TEST4.TEST',
                             'eur',
                             'current',
                             'Test account',
                             max_overdraft=200)
        finac.transaction_create('TEST3.TEST', 1200)
        try:
            finac.transaction_move('TEST2.TEST', 'TEST3.TEST', 2000)
            raise RuntimeError('OverdraftError not raised')
        except finac.OverdraftError:
            self.assertEqual(finac.account_balance('TEST3.TEST'), 300)
コード例 #7
0
 def test097_balance_range(self):
     finac.account_create('tr', 'eur', tp='cash')
     finac.transaction_create('tr', 1000, date='2019-01-05')
     finac.transaction_create('tr', 2000, date='2019-02-05')
     finac.transaction_create('tr', -500, date='2019-04-05')
     finac.transaction_create('tr', -200, date='2019-06-05')
     result.id4test099 = finac.transaction_create('tr',
                                                  800,
                                                  date='2019-08-05')
     self.assertRaises(ValueError,
                       finac.account_balance_range,
                       account='tr',
                       tp='cash',
                       start='2019-01-05',
                       end='2019-8-07',
                       base='usd')
     t, dt = finac.account_balance_range(start='2019-01-05',
                                         account='tr',
                                         end='2019-8-07',
                                         return_timestamp=False)
     self.assertEqual(dt[-4], 2300)
     self.assertEqual(dt[-2], 3100)
     t1, dt1 = finac.account_balance_range(start='2019-01-05',
                                           tp='cash',
                                           end='2019-8-07',
                                           base='usd',
                                           return_timestamp=False)
     self.assertEqual(dt1[-4], 4140)
     self.assertEqual(dt1[-2], 5580)
     res = list(
         finac.exec_query(
             'SELECT account_balance_range('
             'start="2019-01-05", '
             'tp="current|cash", end="2019-8-07", base="usd")'))
     self.assertEqual(res[-4]['balance'], 4140)
     self.assertEqual(res[-2]['balance'], 5580)
コード例 #8
0
 def test070_test_targets_and_tags(self):
     finac.account_create('TT1', 'EUR', tp='credit')
     finac.account_create('TT2', 'EUR', tp='saving')
     finac.transaction_create('TT1', 1000)
     finac.transaction_create('TT2', 1000)
     self.assertEqual(finac.account_balance('TT1'), 1000)
     self.assertEqual(finac.account_balance('TT2'), 1000)
     finac.transaction_create('TT1', target=1500)
     finac.transaction_create('TT2', target=800)
     self.assertEqual(finac.account_balance('TT1'), 1500)
     self.assertEqual(finac.account_balance('TT2'), 800)
     finac.transaction_move('TT1', 'TT2', target_ct=700, tag='loans')
     self.assertEqual(finac.account_balance('TT1'), 1600)
     self.assertEqual(finac.account_balance('TT2'), 700)
     finac.transaction_move('TT2', 'TT1', target_dt=2000, tag='loans')
     self.assertEqual(finac.account_balance('TT1'), 300)
     self.assertEqual(finac.account_balance('TT2'), 2000)
     self.assertEqual(
         len(list(finac.account_statement('TT1', tag='lo;an"s'))), 2)
     print()
     finac.ls('TT2')
     print()
コード例 #9
0
 def test402_transaction_copy(self):
     finac.account_create('test.usd', 'usd')
     finac.account_create('test.eur', 'eur')
     finac.asset_set_rate('eur/usd', value=1.1)
     t = finac.transaction_create('test.usd',
                                  100,
                                  tag='test',
                                  note='for move test')
     t1 = finac.transaction_move(dt='move.test',
                                 ct='test.usd',
                                 tag='copy 1',
                                 amount=10)
     t_cros = finac.transaction_move(dt='test.eur',
                                     ct='test.usd',
                                     amount=10)
     self.assertRaises(ValueError,
                       finac.tc,
                       transaction_ids=t_cros[1],
                       amount=100)
     finac.tc(transaction_ids=t1, date='2019-11-15', amount=30)
     finac.tc(transaction_ids=[t, t_cros[1]])
コード例 #10
0
 def test041_max_balance(self):
     finac.account_create('TEST5.TEST', 'EUR', max_balance=100)
     finac.account_create('TEST6.TEST', 'EUR', max_balance=100)
     finac.transaction_create('TEST5.TEST', 10)
     try:
         finac.transaction_create('TEST5.TEST', 101)
         raise RuntimeError('OverlimitError not raised')
     except finac.OverlimitError:
         self.assertEqual(finac.account_balance('TEST5.TEST'), 10)
     finac.transaction_create('TEST6.TEST', 100)
     try:
         finac.transaction_move('TEST6.TEST', 'TEST5.TEST', 10)
         raise RuntimeError('OverlimitError not raised')
     except finac.OverlimitError:
         self.assertEqual(finac.account_balance('TEST5.TEST'), 10)
         self.assertEqual(finac.account_balance('TEST6.TEST'), 100)
コード例 #11
0
 def test400_list_complete_delete(self):
     t1 = finac.transaction_create('move.test', 1, mark_completed=False)
     t2 = finac.transaction_create('move1.test', 1, mark_completed=False)
     finac.transaction_complete((t1, t2))
     finac.transaction_delete([t1, t2])