Skip to content

Commit

Permalink
issue #117 - add button for Balance Budget
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Oct 19, 2017
1 parent b7f430b commit 4612357
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 1 deletion.
5 changes: 5 additions & 0 deletions biweeklybudget/biweeklypayperiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

from biweeklybudget import settings
from biweeklybudget.models import Transaction, ScheduledTransaction, Budget
from biweeklybudget.utils import dtnow


@total_ordering
Expand Down Expand Up @@ -118,6 +119,10 @@ def end_date(self):
"""
return self._end_date

@property
def is_in_past(self):
return self.end_date < dtnow().date()

@property
def next(self):
"""
Expand Down
6 changes: 5 additions & 1 deletion biweeklybudget/flaskapp/templates/payperiod.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@
<div class="row">
<div class="col-lg-4 col-md-6">
<div class="panel panel-warning">
<div class="panel-heading">Periodic Budgets - <button type="button" class="btn btn-xs btn-primary" id="btn-budg-txfr-periodic">Transfer</button></div>
<div class="panel-heading">Periodic Budgets - <button type="button" class="btn btn-xs btn-primary" id="btn-budg-txfr-periodic">Transfer</button>
{% if is_in_past %}
<button type="button" class="btn btn-xs btn-success" id="btn-pp-balance-budgets">Balance Budgets</button>
{% endif %}
</div>
<div class="table-responsive">
<table class="table table-bordered" id="pb-table">
<thead>
Expand Down
1 change: 1 addition & 0 deletions biweeklybudget/flaskapp/views/payperiods.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def get(self, period_date):
return render_template(
'payperiod.html',
pp=pp,
is_in_past=pp.is_in_past,
pp_prev_date=pp.previous.start_date,
pp_prev_sums=pp.previous.overall_sums,
pp_prev_suffix=self.suffix_for_period(curr_pp, pp.previous),
Expand Down
134 changes: 134 additions & 0 deletions biweeklybudget/tests/acceptance/flaskapp/views/test_payperiods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,140 @@ def test_14_sched_trans_modal_verify_db(self, testdb):
assert t.is_active is True


@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb')
class TestBalanceBudgets(AcceptanceHelper):

def test_00_inactivate_scheduled(self, testdb):
for s in testdb.query(
ScheduledTransaction).filter(
ScheduledTransaction.is_active.__eq__(True)
).all():
s.is_active = False
testdb.add(s)
testdb.flush()
testdb.commit()
# delete existing transactions
for tr in testdb.query(TxnReconcile).all():
testdb.delete(tr)
for idx in [1, 2, 3]:
t = testdb.query(Transaction).get(idx)
testdb.delete(t)
testdb.flush()
testdb.commit()

def test_01_add_transactions(self, testdb):
acct = testdb.query(Account).get(1)
e1budget = testdb.query(Budget).get(1)
e2budget = testdb.query(Budget).get(2)
pp = BiweeklyPayPeriod.period_for_date(
PAY_PERIOD_START_DATE, testdb
)
ppdate = pp.start_date
st8_date = (ppdate + timedelta(days=5))
st8_day = st8_date.day
if st8_day > 28:
st8_day = 28
st = ScheduledTransaction(
account=acct,
budget=e1budget,
amount=11.11,
num_per_period=2,
description='ST7 per_period'
)
testdb.add(st)
testdb.add(ScheduledTransaction(
account=acct,
budget=e1budget,
amount=22.22,
day_of_month=st8_day,
description='ST8 day_of_month'
))
testdb.add(ScheduledTransaction(
account=acct,
budget=e2budget,
amount=33.33,
date=(ppdate + timedelta(days=6)),
description='ST9 date'
))
t = Transaction(
date=(ppdate + timedelta(days=8)),
actual_amount=12.00,
budgeted_amount=11.11,
description='Txn From ST7',
account=acct,
budget=e1budget,
scheduled_trans=st
)
testdb.add(t)
testdb.add(Transaction(
date=(ppdate + timedelta(days=6)),
actual_amount=111.13,
budgeted_amount=111.11,
description='T1foo',
notes='notesT1',
account=acct,
scheduled_trans=testdb.query(ScheduledTransaction).get(1),
budget=e1budget
))
testdb.add(Transaction(
date=(ppdate + timedelta(days=2)),
actual_amount=-333.33,
budgeted_amount=-333.33,
description='T2',
notes='notesT2',
account=testdb.query(Account).get(2),
scheduled_trans=testdb.query(ScheduledTransaction).get(3),
budget=testdb.query(Budget).get(4)
))
testdb.add(Transaction(
date=ppdate,
actual_amount=222.22,
description='T3',
notes='notesT3',
account=testdb.query(Account).get(3),
budget=e2budget
))
testdb.flush()
testdb.commit()
testdb.add(TxnReconcile(note='foo', txn_id=t.id))
testdb.flush()
testdb.commit()

def test_02_curr_period_no_button(self, base_url, selenium, testdb):
p = BiweeklyPayPeriod.period_for_date(PAY_PERIOD_START_DATE, testdb)
self.get(
selenium,
base_url + '/payperiod/' +
p.start_date.strftime('%Y-%m-%d')
)
assert len(
selenium.find_elements_by_id('btn-pp-balance-budgets')
) == 0

def test_03_future_period_no_button(self, base_url, selenium, testdb):
p = BiweeklyPayPeriod.period_for_date(PAY_PERIOD_START_DATE, testdb)
self.get(
selenium,
base_url + '/payperiod/' +
p.next.next.start_date.strftime('%Y-%m-%d')
)
assert len(
selenium.find_elements_by_id('btn-pp-balance-budgets')
) == 0

def test_04_past_period_has_button(self, base_url, selenium, testdb):
p = BiweeklyPayPeriod.period_for_date(PAY_PERIOD_START_DATE, testdb)
self.get(
selenium,
base_url + '/payperiod/' +
p.previous.start_date.strftime('%Y-%m-%d')
)
assert len(
selenium.find_elements_by_id('btn-pp-balance-budgets')
) == 1


@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb')
class TestMakeTransModal(AcceptanceHelper):
Expand Down

0 comments on commit 4612357

Please sign in to comment.