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:
29
bills.py
29
bills.py
@@ -2,6 +2,7 @@ from db import set_bill_type_growth, new_bill, deleteFutureEstimates, get_financ
|
||||
from calc import calc_key_dates
|
||||
from defines import END_YEAR
|
||||
import datetime
|
||||
import re
|
||||
from datetime import date, timedelta
|
||||
|
||||
|
||||
@@ -238,6 +239,8 @@ def actually_add_estimated_new_quarter_bill_forced( bill_type, bill_info, yr, q
|
||||
# NOTE: ALWAYS called for first year - don't always add bills/see below
|
||||
def add_missing_monthly_bills_in_yr( bill_type, bill_info, yr ):
|
||||
|
||||
print( f"add_missing_monthly_bills_in_yr for ( bt={bill_type} -- yr={yr} )" )
|
||||
|
||||
# start date arithmetic from first bill (this is possibly an issue if monthly is not
|
||||
# really perfectly the same each month, but its only for an estimate so should be ok
|
||||
dd = bill_info[bill_type]['first_bill']['bill_date'][8:]
|
||||
@@ -295,8 +298,18 @@ def get_growth_value( bt, bill_type ):
|
||||
return el['ann_growth_min']
|
||||
elif which == 'simple':
|
||||
return el['ann_growth_simple']
|
||||
else:
|
||||
elif which == 'max':
|
||||
return el['ann_growth_max']
|
||||
elif which == 'cpi':
|
||||
finance_data = get_finance_data()
|
||||
return finance_data['Inflation']
|
||||
else:
|
||||
match = re.match("flat-(\d+)", which )
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
else:
|
||||
print( f"FAILED TO GET_GROWTH_VALUE --> which={which}" )
|
||||
return 0
|
||||
|
||||
|
||||
################################################################################
|
||||
@@ -405,7 +418,7 @@ def deal_with_future_car_bills( key_dates, future_car_bills, bill_info ):
|
||||
amt=fb['amount']
|
||||
bt=fb['bill_type']
|
||||
# factor in growth for next bill
|
||||
for yr in range( int(car_yr), END_YEAR ):
|
||||
for yr in range( int(car_yr), END_YEAR+1 ):
|
||||
new_date=f"{yr}-{car_mmdd}"
|
||||
# if we dont already have an annual bill for this year (all car bills are annual)
|
||||
if yr not in bill_info[bt]['year']:
|
||||
@@ -428,7 +441,7 @@ def deal_with_future_D_quit_bills( key_dates, future_D_quit_bills, bill_info ):
|
||||
bt=fb['bill_type']
|
||||
if bill_info[bt]['num_ann_bills'] == 1:
|
||||
# factor in growth for next bill
|
||||
for yr in range( int(D_quit_yr), END_YEAR ):
|
||||
for yr in range( int(D_quit_yr), END_YEAR+1 ):
|
||||
new_date=f"{yr}-{dq_mm}-{dq_dd}"
|
||||
# if we dont already have an annual bill for this year
|
||||
if not find_this_bill( bt, bill_info, new_date ):
|
||||
@@ -440,7 +453,7 @@ def deal_with_future_D_quit_bills( key_dates, future_D_quit_bills, bill_info ):
|
||||
new_date=f"{D_quit_yr}-{m:02d}-{dq_dd}"
|
||||
if not find_this_bill( bt, bill_info, new_date ):
|
||||
new_estimated_bill( bill_info, yr, bt, amt, new_date )
|
||||
for yr in range( int(D_quit_yr)+1, END_YEAR ):
|
||||
for yr in range( int(D_quit_yr)+1, END_YEAR+1 ):
|
||||
amt += amt * bill_info[bt]['growth']/100
|
||||
for m in range( 1, 13):
|
||||
new_date=f"{yr}-{m:02d}-{dq_dd}"
|
||||
@@ -614,7 +627,6 @@ def recalcFutureBills():
|
||||
print("Recalculating future bills as we changed a key date" )
|
||||
finance_data = get_finance_data()
|
||||
key_dates = calc_key_dates( finance_data )
|
||||
finance_data = get_finance_data()
|
||||
bill_data = get_bill_data("order_by_date_only")
|
||||
bill_types = get_bill_types()
|
||||
bill_freqs = get_bill_freqs()
|
||||
@@ -623,7 +635,6 @@ def recalcFutureBills():
|
||||
# this maps freq to bills per annum (e.g. id=2 to 4 bills per annum)
|
||||
bf_id_num = {row["id"]: row["num_bills_per_annum"] for row in bill_freqs}
|
||||
|
||||
|
||||
getFutureBills(bill_data, bill_types, future_car_bills, future_D_quit_bills)
|
||||
deleteFutureEstimates()
|
||||
# deal with future car bills
|
||||
@@ -635,7 +646,7 @@ def recalcFutureBills():
|
||||
# only can use simple growth as its a future bill
|
||||
growth=bill_types[bt]['ann_growth_simple']
|
||||
# factor in growth for next bills
|
||||
for yr in range( int(car_yr), END_YEAR ):
|
||||
for yr in range( int(car_yr), END_YEAR+1 ):
|
||||
new_date=f"{yr}-{car_mmdd}"
|
||||
new_bill( fb['bill_type'], amt, new_date, 1 )
|
||||
amt += amt * growth/100
|
||||
@@ -654,7 +665,7 @@ def recalcFutureBills():
|
||||
num_ann_bills= bf_id_num[bt_id_freq[bt]]
|
||||
if num_ann_bills == 1:
|
||||
# factor in growth for next bill
|
||||
for yr in range( int(D_quit_yr), END_YEAR ):
|
||||
for yr in range( int(D_quit_yr), END_YEAR+1 ):
|
||||
new_date=f"{yr}-{dq_mm}-{dq_dd}"
|
||||
# if we dont already have an annual bill for this year
|
||||
new_bill( fb['bill_type'], amt, new_date, 1 )
|
||||
@@ -664,7 +675,7 @@ def recalcFutureBills():
|
||||
for m in range( int(dq_mm), 13):
|
||||
new_date=f"{D_quit_yr}-{m:02d}-{dq_dd}"
|
||||
new_bill( fb['bill_type'], amt, new_date, 1 )
|
||||
for yr in range( int(D_quit_yr)+1, END_YEAR ):
|
||||
for yr in range( int(D_quit_yr)+1, END_YEAR+1 ):
|
||||
amt += amt * growth/100
|
||||
for m in range( 1, 13):
|
||||
new_date=f"{yr}-{m:02d}-{dq_dd}"
|
||||
|
||||
Reference in New Issue
Block a user