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()
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)
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]])
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()
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)
def test080_lazy_exchange(self): finac.account_create('eur1', 'eur') finac.account_create('usd1', 'usd') if not config.remote: finac.core.config_set('lazy_exchange', False) try: finac.transaction_move('usd1', 'eur1', 20) raise RuntimeError( 'Lazy exchange is off but asset mismatch not detected') except ValueError: pass finac.core.config_set('lazy_exchange', True) time.sleep(0.6) finac.asset_set_rate('EUR/USD', value=1.1) finac.transaction_move('usd1', 'eur1', 20, xdt=False) self.assertEqual(finac.account_balance('eur1'), -20) self.assertEqual(finac.account_balance('usd1'), 22) finac.transaction_move('usd1', 'eur1', 20) self.assertEqual(finac.account_balance('eur1'), -38.18) self.assertEqual(finac.account_balance('usd1'), 42) t1, t2 = finac.transaction_move('usd1', 'eur1', 20, rate=1.25) self.assertEqual(finac.account_balance('eur1'), -54.18) self.assertEqual(finac.account_balance('usd1'), 62) finac.transaction_delete(t1) self.assertEqual(finac.account_balance('eur1'), -38.18) self.assertEqual(finac.account_balance('usd1'), 42) t1, t2 = finac.transaction_move('usd1', 'eur1', 20, rate=1.25) self.assertEqual(finac.account_balance('eur1'), -54.18) self.assertEqual(finac.account_balance('usd1'), 62) finac.transaction_delete(t2) self.assertEqual(finac.account_balance('eur1'), -38.18) self.assertEqual(finac.account_balance('usd1'), 42)
def test005_transaction_move(self): result.transaction2_id = finac.transaction_move( 'TEST2.TEST', 'TEST.TEST', 25, 'test', 'Test move') self.assertEqual(finac.account_balance('TEST.TEST'), 75) self.assertEqual(finac.account_balance('TEST2.TEST'), 25)
def test030_delete_account_and_movements(self): finac.transaction_move('TEST2.TEST', 'TEST.TEST', 60, 'test', 'Test move') finac.account_delete('TEST.TEST') self.assertEqual(finac.account_balance('TEST2.TEST'), 60)