Skip to content

Commit

Permalink
issue #178 - update Transactions view datatable for split-budget tran…
Browse files Browse the repository at this point in the history
…sactions
  • Loading branch information
jantman committed Mar 18, 2018
1 parent 932d7a0 commit 4fdda36
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
22 changes: 21 additions & 1 deletion biweeklybudget/flaskapp/static/js/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,27 @@ $(document).ready(function() {
{
data: "DT_RowData.budget",
"render": function(data, type, row) {
return $("<div>").append($("<a/>").attr("href", "/budgets/" + row.DT_RowData.budget_id).text(data)).html();
if(row.DT_RowData.budgets.length == 1) {
var budg = row.DT_RowData.budgets[0];
var txt = budg['name'];
if(budg['is_income'] === true) { txt = txt + ' (income)'; }
txt = txt + ' (' + budg['id'] + ')';
return $("<div>").append($("<a/>").attr("href", "/budgets/" + budg['id']).text(txt)).html();
} else {
var div = $("<div>");
for (index = 0; index < row.DT_RowData.budgets.length; ++index) {
var budg = row.DT_RowData.budgets[index];
console.log(budg);
console.log(index);
var txt = budg['name'];
if(budg['is_income'] === true) { txt = txt + ' (income)'; }
txt = txt + ' (' + budg['id'] + ')';
txt = txt + ' (' + fmt_currency(budg['amount']) + ')';
div.append($("<a/>").attr("href", "/budgets/" + budg['id']).text(txt));
if(index < row.DT_RowData.budgets.length - 1) { div.append($('<br />')); }
}
return div.html();
}
}
},
{
Expand Down
21 changes: 13 additions & 8 deletions biweeklybudget/flaskapp/views/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,19 @@ def get(self):
)
table.add_data(
acct_id=lambda o: o.account_id,
budget_id=lambda o: o.budget_transactions[0].budget_id,
id=lambda o: o.id,
budget=lambda o: "{} {}({})".format(
o.budget_transactions[0].budget.name,
'(income) '
if o.budget_transactions[0].budget.is_income else '',
o.budget_transactions[0].budget_id
)
budgets=lambda o: [
{
'name': bt.budget.name,
'id': bt.budget_id,
'amount': bt.amount,
'is_income': bt.budget.is_income
}
for bt in sorted(
o.budget_transactions, key=lambda x: x.amount,
reverse=True
)
],
id=lambda o: o.id
)
if args['search[value]'] != '':
table.searchable(lambda qs, s: self._filterhack(qs, s, args_dict))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_table(self, selenium):
'$322.32',
'T4split',
'CreditOne (3)',
'Periodic2 (2)',
'Periodic2 (2) ($222.22)\nPeriodic1 (1) ($100.10)',
'',
'',
''
Expand All @@ -139,6 +139,7 @@ def test_table(self, selenium):
]
for c in elems
]
assert len(linkcols) == 4
assert linkcols[0] == [
'<a href="javascript:transModal(1, mytable)">T1foo</a>',
'<a href="/accounts/1">BankOne (1)</a>',
Expand All @@ -160,6 +161,14 @@ def test_table(self, selenium):
'&nbsp;',
'&nbsp;'
]
assert linkcols[3] == [
'<a href="javascript:transModal(4, mytable)">T4split</a>',
'<a href="/accounts/3">CreditOne (3)</a>',
'<a href="/budgets/2">Periodic2 (2) ($222.22)</a><br>'
'<a href="/budgets/1">Periodic1 (1) ($100.10)</a>',
'&nbsp;',
'&nbsp;'
]

def test_acct_filter_opts(self, selenium):
self.get(selenium, self.baseurl + '/transactions')
Expand Down

0 comments on commit 4fdda36

Please sign in to comment.