Skip to content

Commit

Permalink
issue #178 - budget split for reconcile modal
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Mar 21, 2018
1 parent 6a26067 commit 4509920
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
2 changes: 1 addition & 1 deletion biweeklybudget/flaskapp/static/js/reconcile.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function reconcileTransDiv(trans) {
div += '<div class="col-lg-3">' + fmt_currency(trans['actual_amount']) + '</div>';
div += '<div class="col-lg-3"><strong>Acct:</strong> <span style="white-space: nowrap;"><a href="/accounts/' + trans['account_id'] + '">' + trans['account_name'] + ' (' + trans['account_id'] + ')</a></span></div>';
div += '<div class="col-lg-3"><strong>Budget:</strong> <span style="white-space: nowrap;">';
for (index = 0; index < trans['budgets'].length; ++index) {
for (var index = 0; index < trans['budgets'].length; ++index) {
var budg = trans['budgets'][index];
var txt = budg['name'];
txt = txt + ' (' + budg['id'] + ')';
Expand Down
13 changes: 12 additions & 1 deletion biweeklybudget/flaskapp/static/js/reconcile_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ function txnReconcileModalDiv(msg) {
frm += '<tr><th>Budgeted Amount</th><td>' + fmt_currency(msg['transaction']['budgeted_amount']) + '</td></tr>\n';
frm += '<tr><th>Description</th><td>' + msg['transaction']['description'] + '</td></tr>\n';
frm += '<tr><th>Account</th><td><a href="/accounts/' + msg['acct_id'] + '">' + msg['acct_name'] + ' (' + msg['acct_id'] + ')</a></td></tr>\n';
frm += '<tr><th>Budget</th><td><a href="/budgets/' + msg['budget_id'] + '">' + msg['budget_name'] + ' (' + msg['budget_id'] + ')</a></td></tr>\n';
frm += '<tr><th>Budget</th><td>';
for (var index = 0; index < msg['transaction']['budgets'].length; ++index) {
var budg = msg['transaction']['budgets'][index];
var txt = budg['name'];
txt = txt + ' (' + budg['id'] + ')';
if (msg['transaction']['budgets'].length > 1) {
txt = txt + ' (' + fmt_currency(budg['amount']) + ')';
}
frm += '<a href="/budgets/' + budg['id'] + '">' + txt + '</a>';
if(index < msg['transaction']['budgets'].length - 1) { frm += '<br>'; }
}
frm += '</td></tr>\n';
frm += '<tr><th>Notes</th><td>' + msg['transaction']['notes'] + '</td></tr>\n';
frm += '<tr><th>Scheduled?</th><td>';
if (msg['transaction']['scheduled_trans_id'] !== null) {
Expand Down
4 changes: 1 addition & 3 deletions biweeklybudget/flaskapp/views/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def get(self, reconcile_id):

res = {
'reconcile': rec.as_dict,
'transaction': rec.transaction.as_dict,
'budget_name': rec.transaction.budget_transactions[0].budget.name,
'budget_id': rec.transaction.budget_transactions[0].budget_id,
'transaction': rec.transaction.as_dict
}
res['transaction']['budgets'] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,80 @@ def test_1_modal(self, base_url, selenium):
ofx_elems = self.tbody2elemlist(ofx_tbl)
assert ofx_elems[1][1].get_attribute('innerHTML') == '<a href=' \
'"/accounts/1">BankOne (1)</a>'

def test_2_split_trans(self, testdb):
b1 = testdb.query(Budget).get(1) # Periodic1
b2 = testdb.query(Budget).get(2) # Periodic2
t = testdb.query(Transaction).get(1)
t.set_budget_amounts({
b1: Decimal('110.02'),
b2: Decimal('1.11')
})
testdb.commit()

def test_3_split_trans_modal(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/transactions')
link = selenium.find_element_by_xpath(
'//a[@href="javascript:txnReconcileModal(1)"]')
modal, title, body = self.try_click_and_get_modal(selenium, link)
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Transaction Reconcile 1'
dl = body.find_element_by_tag_name('dl')
assert dl.get_attribute('innerHTML') == '\n' \
'<dt>Date Reconciled</dt><dd>2017-04-10 08:09:11 UTC</dd>\n' \
'<dt>Note</dt><dd>reconcile notes</dd>\n' \
'<dt>Rule</dt><dd>null</dd>\n'
trans_tbl = body.find_element_by_id('txnReconcileModal-trans')
trans_texts = self.tbody2textlist(trans_tbl)
assert trans_texts == [
['Transaction'],
[
'Date',
(dtnow() + timedelta(days=4)).strftime('%Y-%m-%d')
],
['Amount', '$111.13'],
['Budgeted Amount', '$111.11'],
['Description', 'T1foo'],
['Account', 'BankOne (1)'],
['Budget', 'Periodic1 (1) ($110.02)\nPeriodic2 (2) ($1.11)'],
['Notes', 'notesT1'],
['Scheduled?', 'Yes (1)']
]
trans_elems = self.tbody2elemlist(trans_tbl)
assert trans_elems[5][1].get_attribute('innerHTML') == '<a href=' \
'"/accounts/1">BankOne (1)</a>'
assert trans_elems[6][1].get_attribute('innerHTML') == '<a href=' \
'"/budgets/1">Periodic1 (1) ($110.02)</a><br><a href=' \
'"/budgets/2">Periodic2 (2) ($1.11)</a>'
assert trans_elems[8][1].get_attribute('innerHTML') == '<a href=' \
'"/scheduled/1">Yes (1)</a>'
ofx_tbl = body.find_element_by_id('txnReconcileModal-ofx')
ofx_texts = self.tbody2textlist(ofx_tbl)
assert ofx_texts == [
['OFX Transaction'],
['Account', 'BankOne (1)'],
['FITID', 'BankOne.0.1'],
['Date Posted', (dtnow() - timedelta(days=6)).strftime('%Y-%m-%d')],
['Amount', '-$20.00'],
['Name', 'Late Fee'],
['Memo', ''],
['Type', 'Debit'],
['Description', ''],
['Notes', ''],
['Checknum', ''],
['MCC', ''],
['SIC', ''],
['OFX Statement'],
['ID', '1'],
['Date', (dtnow() - timedelta(hours=46)).strftime('%Y-%m-%d')],
['Filename', '/stmt/BankOne/0'],
[
'File mtime',
(dtnow() - timedelta(hours=46)).strftime('%Y-%m-%d')
],
['Ledger Balance', '$12,345.67']
]
ofx_elems = self.tbody2elemlist(ofx_tbl)
assert ofx_elems[1][1].get_attribute('innerHTML') == '<a href=' \
'"/accounts/1">BankOne (1)</a>'

0 comments on commit 4509920

Please sign in to comment.