make radio button for min / avg / max growth value be pushed into which_growth in the DB for bill_type row, then also delete estimated bills for that bill_type, and then calling /bills, causes the estimated bills to be filled back in based on the new chosen growth model
This commit is contained in:
16
bills.py
16
bills.py
@@ -71,6 +71,20 @@ def add_missing_monthly_bills_in_yr( bill_type, bill_info, yr ):
|
||||
new_bill( bill_type, amt, new_date, 1 )
|
||||
return
|
||||
|
||||
# given the bill_type has a which_growth contain min/avg/max, return the corresponding growth number
|
||||
def get_growth_value( bt, bill_type ):
|
||||
for el in bt:
|
||||
if el['id'] == bill_type:
|
||||
which = el['which_growth']
|
||||
break
|
||||
|
||||
if which == 'avg':
|
||||
return el['ann_growth_avg']
|
||||
elif which == 'min':
|
||||
return el['ann_growth_min']
|
||||
else:
|
||||
return el['ann_growth_max']
|
||||
|
||||
|
||||
# go through the bill data from the DB, put it into more friendly formats, then
|
||||
# work out and then add missing bill data (might be b/c we have monthly bills,
|
||||
@@ -94,7 +108,7 @@ def process_bill_data(bd, bt, bf):
|
||||
# new bill type
|
||||
if not bill_type in bill_info:
|
||||
bill_info[bill_type]={}
|
||||
bill_info[bill_type]['growth'] = bt_id_ann_growth_avg[bill_type]
|
||||
bill_info[bill_type]['growth'] = get_growth_value( bt, bill_type )
|
||||
bill_info[bill_type]['num_ann_bills'] = bf_id_num[bt_id_freq[bill_type]]
|
||||
bill_info[bill_type]['first_bill']={}
|
||||
bill_info[bill_type]['last_bill']={}
|
||||
|
||||
10
db.py
10
db.py
@@ -278,6 +278,16 @@ def get_bill_types():
|
||||
conn.close()
|
||||
return bt
|
||||
|
||||
def use_growth( bill_type, which_growth ):
|
||||
conn = connect_db(False)
|
||||
cur = conn.cursor()
|
||||
cur.execute( f"update bill_type set which_growth = '{which_growth}' where id = {bill_type}" )
|
||||
# okay, new growth type being used, delete old estimated bills are recreate them
|
||||
cur.execute( f"delete from bill_data where estimated=1 and bill_type = {bill_type}" )
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return
|
||||
|
||||
def get_bill_freqs():
|
||||
conn = connect_db(True)
|
||||
cur = conn.cursor()
|
||||
|
||||
8
main.py
8
main.py
@@ -3,7 +3,7 @@ from flask import Flask, render_template, request, redirect, url_for, Response,
|
||||
from calc import calculate_savings_depletion
|
||||
from db import init_db, get_finance_data, update_finance, get_budget_data, insert_cset, get_comp_set_data, get_comp_set_options, get_bill_freqs
|
||||
from db import get_bill_data, new_bill, update_bill_data, delete_bill
|
||||
from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type
|
||||
from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type, use_growth
|
||||
from bills import process_bill_data
|
||||
from collections import defaultdict, Counter
|
||||
from datetime import datetime
|
||||
@@ -185,6 +185,12 @@ def DeleteBill():
|
||||
delete_bill( data['id'] )
|
||||
return "200"
|
||||
|
||||
@app.route('/usegrowth', methods=['POST'])
|
||||
def UseGrowth():
|
||||
data = request.get_json()
|
||||
use_growth( data['bill_type'], data['which_growth'] )
|
||||
return "200"
|
||||
|
||||
# Main program
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
||||
@@ -54,18 +54,21 @@
|
||||
<script>$('#bill-type-freq-{{bt.id}}').val( {{bt.freq}} );</script>
|
||||
<div class="px-0 col-2">
|
||||
<div class="btn-group w-100" role="group">
|
||||
<input type="radio" class="btn-check" name="bill-type-growth-{{bt.id}}" id="bill-type-growth-min-{{bt.id}}" autocomplete="off" value=min-g-{{bt.id}}>
|
||||
<label class="btn btn-outline-secondary" for="bill-type-growth-min-{{bt.id}}">
|
||||
<input type="radio" class="btn-check" name="growth-{{bt.id}}" id="min-{{bt.id}}" autocomplete="off"
|
||||
onChange="UseGrowth({{bt.id}}, 'min')" {% if bt.which_growth == 'min' %}checked{% endif %}>
|
||||
<label class="btn btn-outline-secondary" for="min-{{bt.id}}">
|
||||
{% if bt.ann_growth_min < 10 %} {% endif %}
|
||||
{{'%.2f'|format(bt.ann_growth_min)}}
|
||||
</label>
|
||||
<input type="radio" class="btn-check" name="bill-type-growth-{{bt.id}}" id="bill-type-growth-avg-{{bt.id}}" autocomplete="off" checked value=avg-g-{{bt.id}}>
|
||||
<label class="btn btn-outline-secondary" for="bill-type-growth-avg-{{bt.id}}">
|
||||
<input type="radio" class="btn-check" name="growth-{{bt.id}}" id="avg-{{bt.id}}" autocomplete="off"
|
||||
onChange="UseGrowth({{bt.id}}, 'avg')" {% if bt.which_growth == 'avg' %}checked{% endif %}>
|
||||
<label class="btn btn-outline-secondary" for="avg-{{bt.id}}">
|
||||
{% if bt.ann_growth_avg < 10 %} {% endif %}
|
||||
{{'%.2f'|format(bt.ann_growth_avg)}}
|
||||
</label>
|
||||
<input type="radio" class="btn-check" name="bill-type-growth-{{bt.id}}" id="bill-type-growth-max-{{bt.id}}" autocomplete="off" value=max-g-{{bt.id}}>
|
||||
<label class="btn btn-outline-secondary" for="bill-type-growth-max-{{bt.id}}">
|
||||
<input type="radio" class="btn-check" name="growth-{{bt.id}}" id="max-{{bt.id}}" autocomplete="off"
|
||||
onChange="UseGrowth({{bt.id}}, 'max')" {% if bt.which_growth == 'max' %}checked{% endif %}>
|
||||
<label class="btn btn-outline-secondary" for="max-{{bt.id}}">
|
||||
{% if bt.ann_growth_max < 10 %} {% endif %}
|
||||
{{'%.2f'|format(bt.ann_growth_max)}}
|
||||
</label>
|
||||
@@ -310,6 +313,12 @@
|
||||
data: JSON.stringify( { 'id': id } ), success: function() { window.location='bills' } } )
|
||||
}
|
||||
|
||||
function UseGrowth( bt, which )
|
||||
{
|
||||
$.ajax( { type: 'POST', url: '/usegrowth', contentType: 'application/json',
|
||||
data: JSON.stringify( { 'bill_type': bt, 'which_growth': which } ), success: function() { window.location='bills' } } )
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
// if amount has enter key in it then save, but dont do this for other fields in new bill
|
||||
$("#new-bill-data-amount").keyup(function(event){ if(event.which == 13){ $("#save-bill").click(); } event.preventDefault(); });
|
||||
|
||||
Reference in New Issue
Block a user