Skip to content

Commit

Permalink
fixes #196 - don't include inactive budgets in Transation Modal budge…
Browse files Browse the repository at this point in the history
…t selects, unless already using that budget
  • Loading branch information
jantman committed Aug 20, 2018
1 parent 3a3146c commit 90cf1e7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Unreleased Changes

* `Issue #198 <https://github.com/jantman/biweeklybudget/issues/198>`_ - Fix broken method of retrieving current US Prime Rate. Previously we used marketwatch.com for this but they've introduced javascript-based bot protection on their site (which is ironic since we were reading a value from the page's ``meta`` tags, which are specifically intended to be read by machines). Switch to using wsj.com instead and (ugh) parsing a HTML table. This *will* break when the format of the table changes. As previously, we cache this value in the DB for 48 hours in order to be a good citizen.
* `Issue #197 <https://github.com/jantman/biweeklybudget/issues/197>`_ - Add notification for case where balance of all budget-funding accounts is *more* than sum of standing budgets, current payperiod remaining, and unreconciled. This is the opposite of the similar notification that already exists, intended to detect if there is money in accounts not accounted for in the budgets.
* `Issue #196 <https://github.com/jantman/biweeklybudget/issues/196>`_ - Don't include inactive budgets in Budget select elements on Transaction Modal form, unless it's an existing Transaction using that budget.

1.0.0 (2018-07-07)
------------------
Expand Down
30 changes: 27 additions & 3 deletions biweeklybudget/flaskapp/static/js/transactions_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var validation_count = 0; // helper for acceptance testing of validation logic
* Generate the HTML for the form on the Modal
*/
function transModalDivForm() {

return new FormBuilder('transForm')
.addHidden('trans_frm_id', 'id', '')
.addDatePicker('trans_frm_date', 'date', 'Date')
Expand All @@ -52,7 +53,7 @@ function transModalDivForm() {
{ inputHtml: 'onchange="transModalHandleSplit()"' }
)
.addHTML('<div id="budgets-error-div-container"><div id="budgets-error-div" name="budgets"></div></div>')
.addLabelToValueSelect('trans_frm_budget', 'budget', 'Budget', budget_names_to_id, 'None', true)
.addLabelToValueSelect('trans_frm_budget', 'budget', 'Budget', active_budget_names_to_id, 'None', true)
.addHTML(
'<div id="trans_frm_split_budget_container" style="display: none;">' +
'<p style="font-weight: 700; margin-bottom: 5px;">Budgets</p>' +
Expand Down Expand Up @@ -113,13 +114,36 @@ function transModalDivFillAndShow(msg) {
* @param {number} budg_id - The ID of the budget to select.
*/
function selectBudget(sel_num, budg_id) {
var budg_name = getObjectValueKey(active_budget_names_to_id, budg_id);
if(sel_num == null) {
if(budg_name == null) {
// append the select option
$('#trans_frm_budget').append('<option value="' + budg_id + '">' + budg_name + '</option>');
}
$('#trans_frm_budget option[value=' + budg_id + ']').prop('selected', 'selected').change();
} else {
if(budg_name == null) {
// append the select option
$('#trans_frm_budget_' + sel_num).append('<option value="' + budg_id + '">' + budg_name + '</option>');
}
$('#trans_frm_budget_' + sel_num + ' option[value=' + budg_id + ']').prop('selected', 'selected').change();
}
}

/**
* Return the first property of ``obj`` with ``val`` as its value, or null.
* @param obj the object to check
* @param val the value to look for
*/
function getObjectValueKey(obj, val) {
Object.keys(obj).forEach(function (key) {
if(obj[key] == val) {
return key;
}
});
return null;
}

/**
* Show the Transaction modal popup, optionally populated with
* information for one Transaction. This function calls
Expand Down Expand Up @@ -282,8 +306,8 @@ function transModalBudgetSplitRowHtml(row_num) {
html += '<div class="form-group" id="trans_frm_budget_group_' + row_num + '" style="float: left; width: 75%;">';
html += '<select id="trans_frm_budget_' + row_num + '" name="budget_' + row_num + '" class="form-control" onblur="budgetSplitBlur()" onchange="transModalSplitBudgetChanged(' + row_num + ')">';
html += '<option value="None"></option>';
Object.keys(budget_names_to_id).forEach(function (key) {
html += '<option value="' + budget_names_to_id[key] + '">' + key + '</option>'
Object.keys(active_budget_names_to_id).forEach(function (key) {
html += '<option value="' + active_budget_names_to_id[key] + '">' + key + '</option>'
});
html += '</select>';
html += '</div>'; // .form-group #trans_frm_budget_group
Expand Down
4 changes: 4 additions & 0 deletions biweeklybudget/flaskapp/templates/payperiod.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
{% for id in budgets.keys()|sort %}
budget_names_to_id["{{ budgets[id] }}"] = "{{ id }}";
{% endfor %}
var active_budget_names_to_id = {};
{% for id in active_budgets.keys()|sort %}
active_budget_names_to_id["{{ active_budgets[id] }}"] = "{{ id }}";
{% endfor %}
</script>
{% endblock %}
{% block body %}
Expand Down
4 changes: 4 additions & 0 deletions biweeklybudget/flaskapp/templates/reconcile.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
{% for id in budgets.keys()|sort %}
budget_names_to_id["{{ budgets[id] }}"] = "{{ id }}";
{% endfor %}
var active_budget_names_to_id = {};
{% for id in active_budgets.keys()|sort %}
active_budget_names_to_id["{{ active_budgets[id] }}"] = "{{ id }}";
{% endfor %}

// store state for reconciled transactions - dict of Trans ID to
// Array of [OFX account_id, OFX fitid]
Expand Down
4 changes: 4 additions & 0 deletions biweeklybudget/flaskapp/templates/transactions.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
{% for name in budgets.keys()|sort %}
budget_names_to_id["{{ name }}"] = {{ budgets[name] }};
{% endfor %}
var active_budget_names_to_id = {};
{% for name in active_budgets.keys()|sort %}
active_budget_names_to_id["{{ name }}"] = {{ active_budgets[name] }};
{% endfor %}
</script>
{% endblock %}
{% block body %}
Expand Down
6 changes: 5 additions & 1 deletion biweeklybudget/flaskapp/views/payperiods.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ def get(self, period_date):
pp = BiweeklyPayPeriod.period_for_date(d, db_session)
curr_pp = BiweeklyPayPeriod.period_for_date(dtnow(), db_session)
budgets = {}
active_budgets = {}
for b in db_session.query(Budget).all():
k = b.name
if b.is_income:
k = '%s (i)' % b.name
budgets[b.id] = k
if b.is_active:
active_budgets[b.id] = k
standing = {
b.id: b.current_balance
for b in db_session.query(Budget).filter(
Expand Down Expand Up @@ -173,7 +176,8 @@ def get(self, period_date):
periodic=periodic,
transactions=pp.transactions_list,
accts=accts,
txfr_date_str=txfr_date_str
txfr_date_str=txfr_date_str,
active_budgets=active_budgets
)


Expand Down
6 changes: 5 additions & 1 deletion biweeklybudget/flaskapp/views/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ class ReconcileView(MethodView):

def get(self):
budgets = {}
active_budgets = {}
for b in db_session.query(Budget).all():
k = b.name
if b.is_income:
k = '%s (i)' % b.name
budgets[b.id] = k
if b.is_active:
active_budgets[b.id] = k
accts = {a.name: a.id for a in db_session.query(Account).all()}
return render_template(
'reconcile.html',
budgets=budgets,
accts=accts
accts=accts,
active_budgets=active_budgets
)


Expand Down
22 changes: 16 additions & 6 deletions biweeklybudget/flaskapp/views/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ def get(self):
"""
accts = {a.name: a.id for a in db_session.query(Account).all()}
budgets = {}
active_budgets = {}
for b in db_session.query(Budget).all():
if b.is_income:
budgets['%s (income)' % b.name] = b.id
bname = '%s (income)' % b.name
else:
budgets[b.name] = b.id
bname = b.name
budgets[bname] = b.id
if b.is_active:
active_budgets[bname] = b.id
return render_template(
'transactions.html',
accts=accts,
budgets=budgets
budgets=budgets,
active_budgets=active_budgets
)


Expand All @@ -85,16 +90,21 @@ def get(self, trans_id):
"""
accts = {a.name: a.id for a in db_session.query(Account).all()}
budgets = {}
active_budgets = {}
for b in db_session.query(Budget).all():
if b.is_income:
budgets['%s (income)' % b.name] = b.id
bname = '%s (income)' % b.name
else:
budgets[b.name] = b.id
bname = b.name
budgets[bname] = b.id
if b.is_active:
active_budgets[bname] = b.id
return render_template(
'transactions.html',
accts=accts,
budgets=budgets,
trans_id=trans_id
trans_id=trans_id,
active_budgets=active_budgets
)


Expand Down

0 comments on commit 90cf1e7

Please sign in to comment.