redid bills UI, you can now choose CPI or FLAT X% as well, via a drop-down not a set of buttons. The changing of inflation also tweaks any bills using CPI, all works
This commit is contained in:
28
main.py
28
main.py
@@ -1,9 +1,11 @@
|
||||
# main.py
|
||||
from flask import Flask, render_template, request, redirect, url_for, Response, jsonify
|
||||
from calc import calculate_savings_depletion, calc_key_dates
|
||||
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, delete_estimated_bills
|
||||
from db import get_bill_ui, save_ui, delete_cset
|
||||
from db import init_db, get_finance_data, update_finance, get_budget_data
|
||||
from db import insert_cset, get_comp_set_data, get_comp_set_options, delete_cset
|
||||
from db import get_bill_freqs, get_bill_growth_types
|
||||
from db import get_bill_data, new_bill, update_bill_data, delete_bill, delete_estimated_bills, delete_estimated_bills_for
|
||||
from db import get_bill_ui, save_ui
|
||||
from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type, use_growth
|
||||
from bills import process_bill_data, calc_future_totals, set_bill_type_growth, recalcFutureBills
|
||||
from defines import END_YEAR
|
||||
@@ -11,6 +13,7 @@ from collections import defaultdict, Counter
|
||||
from datetime import datetime, date
|
||||
import csv
|
||||
import io
|
||||
import requests
|
||||
from disp import FP_VAR
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -148,6 +151,21 @@ def update():
|
||||
# changed Ioniq6_future, Car_buyout_date or D_Num_fortnights_pay, so lets force recalc key_dates, and therefore estimated bills
|
||||
if old_finance_data['D_Num_fortnights_pay'] != new_finance_data['D_Num_fortnights_pay'] or old_finance_data['Ioniq6_future'] != new_finance_data['Ioniq6_future'] or old_finance_data['Car_buyout_date'] != new_finance_data['Car_buyout_date']:
|
||||
recalcFutureBills()
|
||||
if old_finance_data['Inflation'] != new_finance_data['Inflation']:
|
||||
# need to check if any bill type is using CPI, if so, force those future bills to be recalculated
|
||||
bill_types = get_bill_types()
|
||||
for bt in bill_types:
|
||||
if bt['which_growth'] == 'cpi':
|
||||
print( f"OK, changed inflation and need to redo bills for bt_id={bt['id']}" )
|
||||
delete_estimated_bills_for( bt['id'] )
|
||||
#recalc_estimated_bills_for( bt['id'] )
|
||||
# okay, now go through code to recalc bills...
|
||||
base=request.url_root
|
||||
response = requests.get(f"{base}/bills")
|
||||
if response.status_code == 200:
|
||||
print("ALL GOOD")
|
||||
else:
|
||||
print("FFS")
|
||||
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@@ -160,13 +178,14 @@ def DisplayBillData():
|
||||
bill_types = get_bill_types()
|
||||
bill_freqs = get_bill_freqs()
|
||||
bill_ui = get_bill_ui()
|
||||
bill_growth_types = get_bill_growth_types()
|
||||
# take bill data, AND work out estimated future bills - process this into the bill_info array,
|
||||
bill_info=process_bill_data(bill_data, bill_types, bill_freqs, key_dates)
|
||||
# get an array of the total costs of bills each year - purely cosmetic (using bill_info)
|
||||
total=calc_future_totals(bill_info, bill_types)
|
||||
# update/re-get bill_data now that new estimated bills have been added
|
||||
bill_data = get_bill_data("order_by_bill_type_then_date")
|
||||
return render_template('bills.html', bill_data=bill_data, bill_types=bill_types, bill_freqs=bill_freqs, bill_ui=bill_ui, this_year=datetime.today().year, END_YEAR=END_YEAR, total=total, key_dates=key_dates )
|
||||
return render_template('bills.html', bill_data=bill_data, bill_types=bill_types, bill_freqs=bill_freqs, bill_ui=bill_ui, this_year=datetime.today().year, END_YEAR=END_YEAR, total=total, key_dates=key_dates, growth=bill_growth_types, cpi=finance_data['Inflation'] )
|
||||
|
||||
@app.route('/newbilltype', methods=['POST'])
|
||||
def InsertBillType():
|
||||
@@ -224,6 +243,7 @@ def SaveUI():
|
||||
@app.route('/force_recalc_bills', methods=['POST'])
|
||||
def force_recalc_bills():
|
||||
delete_estimated_bills()
|
||||
recalcFutureBills()
|
||||
return "200"
|
||||
|
||||
@app.route('/cset')
|
||||
|
||||
Reference in New Issue
Block a user