Skip to content

Commit

Permalink
issue #105 - WIP more code conversion for model refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Feb 6, 2018
1 parent 89267d7 commit 33194b2
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 36 deletions.
5 changes: 4 additions & 1 deletion biweeklybudget/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class Transaction(Base, ModelAsDict):
actual_amount = Column(Numeric(precision=10, scale=4), nullable=False)

#: Budgeted amount of the transaction, if it was budgeted ahead of time
#: via a :py:class:`~.ScheduledTransaction`.
#: via a :py:class:`~.ScheduledTransaction`. This attribute is only set by
#: :py:meth:`~.SchedToTransFormHandler.submit` and
#: :py:meth:`~.SkipSchedTransFormHandler.submit`. And, for some incorrect
#: reason, by :py:func:`biweeklybudget.models.utils.do_budget_transfer`.
budgeted_amount = Column(Numeric(precision=10, scale=4))

#: description
Expand Down
103 changes: 86 additions & 17 deletions biweeklybudget/tests/acceptance/flaskapp/views/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,100 +241,169 @@ def test_3_add_transactions(self, testdb):
periods = self.pay_periods(testdb)
# previous pay period
ppdate = periods[0].start_date
testdb.add(Transaction(
t1 = Transaction(
date=(ppdate + timedelta(days=1)),
actual_amount=100.00,
budgeted_amount=100.00,
description='prev income',
account=acct,
planned_budget=ibudget
)
testdb.add(t1)
testdb.add(BudgetTransaction(
transaction=t1,
amount=100.00,
budget=ibudget
))
testdb.add(Transaction(
t2 = Transaction(
date=(ppdate + timedelta(days=2)),
actual_amount=250.00,
description='prev trans 1',
account=acct,
account=acct
)
testdb.add(t2)
testdb.add(BudgetTransaction(
transaction=t2,
amount=250.00,
budget=e2budget
))
testdb.add(Transaction(
t3 = Transaction(
date=(ppdate + timedelta(days=3)),
actual_amount=600.00,
budgeted_amount=500.00,
description='prev trans 2',
account=acct,
planned_budget=e1budget
)
testdb.add(t3)
testdb.add(BudgetTransaction(
transaction=t3,
amount=600.00,
budget=e1budget
))
ppdate = periods[1].start_date
testdb.add(Transaction(
t4 = Transaction(
date=(ppdate + timedelta(days=1)),
actual_amount=1400.00,
budgeted_amount=100.00,
description='prev income',
account=acct,
planned_budget=ibudget
)
testdb.add(t4)
testdb.add(BudgetTransaction(
transaction=t4,
amount=1400.00,
budget=ibudget
))
testdb.add(Transaction(
t5 = Transaction(
date=(ppdate + timedelta(days=2)),
actual_amount=1850.00,
description='prev trans 1',
account=acct,
account=acct
)
testdb.add(t5)
testdb.add(BudgetTransaction(
transaction=t5,
amount=1850.00,
budget=e2budget
))
testdb.add(Transaction(
t6 = Transaction(
date=(ppdate + timedelta(days=3)),
actual_amount=600.00,
budgeted_amount=500.00,
description='prev trans 2',
account=acct,
planned_budget=e1budget
)
testdb.add(t6)
testdb.add(BudgetTransaction(
transaction=t6,
amount=600.00,
budget=e1budget
))
ppdate = periods[2].start_date
testdb.add(Transaction(
t7 = Transaction(
date=(ppdate + timedelta(days=1)),
actual_amount=1400.00,
budgeted_amount=100.00,
description='prev income',
account=acct,
planned_budget=ibudget
)
testdb.add(t7)
testdb.add(BudgetTransaction(
transaction=t7,
amount=1400.00,
budget=ibudget
))
testdb.add(Transaction(
t8 = Transaction(
date=(ppdate + timedelta(days=2)),
actual_amount=788.00,
description='prev trans 1',
account=acct,
account=acct
)
testdb.add(t8)
testdb.add(BudgetTransaction(
transaction=t8,
amount=788.00,
budget=e2budget
))
testdb.add(Transaction(
t9 = Transaction(
date=(ppdate + timedelta(days=3)),
actual_amount=600.00,
budgeted_amount=500.00,
description='prev trans 2',
account=acct,
planned_budget=e1budget
)
testdb.add(t9)
testdb.add(BudgetTransaction(
transaction=t9,
amount=600.00,
budget=e1budget
))
ppdate = periods[3].start_date
testdb.add(Transaction(
t10 = Transaction(
date=(ppdate + timedelta(days=1)),
actual_amount=1400.00,
budgeted_amount=100.00,
description='prev income',
account=acct,
planned_budget=ibudget
)
testdb.add(t10)
testdb.add(BudgetTransaction(
transaction=t10,
amount=1400.00,
budget=ibudget
))
testdb.add(Transaction(
t11 = Transaction(
date=(ppdate + timedelta(days=2)),
actual_amount=2.00,
description='prev trans 1',
account=acct,
account=acct
)
testdb.add(t11)
testdb.add(BudgetTransaction(
transaction=t11,
amount=2.00,
budget=e2budget
))
testdb.add(Transaction(
t12 = Transaction(
date=(ppdate + timedelta(days=3)),
actual_amount=600.00,
budgeted_amount=500.00,
description='prev trans 2',
account=acct,
budget=e1budget
planned_budget=e1budget
)
testdb.add(t12)
testdb.add(BudgetTransaction(
transaction=t12,
amount=600.00,
budget=e1budget,
foobarbaz=123
))
testdb.flush()
testdb.commit()
Expand Down
89 changes: 73 additions & 16 deletions biweeklybudget/tests/acceptance/test_biweeklypayperiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from biweeklybudget.tests.acceptance_helpers import AcceptanceHelper
from biweeklybudget.models.scheduled_transaction import ScheduledTransaction
from biweeklybudget.models.transaction import Transaction
from biweeklybudget.models.budget_transaction import BudgetTransaction
from biweeklybudget.models.account import Account, AcctType
from biweeklybudget.models.budget_model import Budget
from biweeklybudget.models.txn_reconcile import TxnReconcile
Expand Down Expand Up @@ -250,10 +251,15 @@ def test_2_add_data(self, testdb):
date=date(2017, 4, 9),
description='Trans_ST_day_9',
account=acct,
budget=budg,
planned_budget=budg,
scheduled_trans=st_daynum,
)
testdb.add(t_daynum)
testdb.add(BudgetTransaction(
transaction=t_daynum,
amount=111.33,
budget=budg
))
testdb.add(TxnReconcile(
note='foo',
transaction=t_daynum
Expand All @@ -280,20 +286,30 @@ def test_2_add_data(self, testdb):
date=date(2017, 4, 14),
description='Trans_ST_pp_3_A',
account=acct,
budget=budg,
planned_budget=budg,
scheduled_trans=st_pp3,
)
testdb.add(t_pp3A)
testdb.add(BudgetTransaction(
transaction=t_pp3A,
amount=333.33,
budget=budg
))
t_pp3B = Transaction(
actual_amount=333.33,
budgeted_amount=333.33,
date=date(2017, 4, 15),
description='Trans_ST_pp_3_B',
account=acct,
budget=budg,
planned_budget=budg,
scheduled_trans=st_pp3
)
testdb.add(t_pp3B)
testdb.add(BudgetTransaction(
transaction=t_pp3B,
amount=333.33,
budget=budg
))
st_date = ScheduledTransaction(
amount=444.44,
description='ST_date',
Expand All @@ -308,26 +324,39 @@ def test_2_add_data(self, testdb):
date=date(2017, 4, 12),
description='Trans_ST_date',
account=acct,
budget=budg,
planned_budget=budg,
scheduled_trans=st_date
)
testdb.add(t_date)
testdb.add(BudgetTransaction(
transaction=t_date,
amount=444.44,
budget=budg
))
t_foo = Transaction(
actual_amount=555.55,
date=date(2017, 4, 8),
description='Trans_foo',
account=acct,
budget=budg
account=acct
)
testdb.add(t_foo)
testdb.add(BudgetTransaction(
transaction=t_foo,
amount=555.55,
budget=budg
))
t_bar = Transaction(
actual_amount=666.66,
date=date(2017, 4, 16),
description='Trans_bar',
account=acct,
budget=budg
account=acct
)
testdb.add(t_bar)
testdb.add(BudgetTransaction(
transaction=t_bar,
amount=666.66,
budget=budg
))
testdb.flush()
testdb.commit()

Expand Down Expand Up @@ -532,12 +561,17 @@ def test_3_add_transactions(self, testdb):
acct = testdb.query(Account).get(1)
budgets = {x.id: x for x in testdb.query(Budget).all()}
# Budget 3 Income Transaction
testdb.add(Transaction(
t1 = Transaction(
date=date(2017, 4, 7),
actual_amount=100.00,
budgeted_amount=100.00,
description='B3 Income',
account=acct,
account=acct
)
testdb.add(t1)
testdb.add(BudgetTransaction(
transaction=t1,
amount=100.00,
budget=budgets[3]
))
# Budget 3 Income ST
Expand All @@ -556,19 +590,30 @@ def test_3_add_transactions(self, testdb):
budget=budgets[4],
date=date(2017, 4, 10)
))
testdb.add(Transaction(
t2 = Transaction(
date=date(2017, 4, 11),
actual_amount=250.00,
description='B4 T no budgeted',
account=acct,
budget=budgets[4]
account=acct
)
testdb.add(t2)
testdb.add(BudgetTransaction(
transaction=t2,
budget=budgets[4],
amount=250.00
))
testdb.add(Transaction(
t3 = Transaction(
date=date(2017, 4, 12),
actual_amount=600.00,
budgeted_amount=500.00,
description='B4 T budgeted',
account=acct,
planned_budget=budgets[4]
)
testdb.add(t3)
testdb.add(BudgetTransaction(
transaction=t3,
amount=600.00,
budget=budgets[4]
))
# Budget 5 budgeted greater than allocated (100)
Expand All @@ -579,12 +624,18 @@ def test_3_add_transactions(self, testdb):
budget=budgets[5],
day_of_month=9
))
testdb.add(Transaction(
t4 = Transaction(
date=date(2017, 4, 13),
description='B5 T',
actual_amount=3.00,
budgeted_amount=1.00,
account=acct,
planned_budget=budgets[5]
)
testdb.add(t4)
testdb.add(BudgetTransaction(
transaction=t4,
amount=3.00,
budget=budgets[5]
))
testdb.flush()
Expand Down Expand Up @@ -662,12 +713,18 @@ def test_6_transaction_list_ordering(self, testdb):
def test_7_spent_greater_than_allocated(self, testdb):
acct = testdb.query(Account).get(1)
budget = testdb.query(Budget).get(5)
testdb.add(Transaction(
t = Transaction(
date=date(2017, 4, 13),
description='B6 T',
actual_amount=2032.0,
budgeted_amount=32.0,
account=acct,
planned_budget=budget
)
testdb.add(t)
testdb.add(BudgetTransaction(
transaction=t,
amount=2032.0,
budget=budget
))
testdb.flush()
Expand Down
Loading

0 comments on commit 33194b2

Please sign in to comment.