add support for simple growth, also remove all estimated bills when we add a new real bill

This commit is contained in:
2025-08-28 19:46:51 +10:00
parent 89fe874c5c
commit 91ebc227b6

14
db.py
View File

@@ -91,6 +91,7 @@ def init_db():
ann_growth_min REAL, ann_growth_min REAL,
ann_growth_avg REAL, ann_growth_avg REAL,
ann_growth_max REAL, ann_growth_max REAL,
ann_growth_simple REAL,
FOREIGN KEY(freq) REFERENCES bill_freq(id) FOREIGN KEY(freq) REFERENCES bill_freq(id)
)''') )''')
@@ -148,8 +149,8 @@ def get_finance_data():
return dict(finance) return dict(finance)
def get_budget_data(finance_data): def get_budget_data(finance_data):
# annual bills - health ins (5k), rates (2.4), electricity (1.5), gas (2), internet (1.6), car insurance (.7), rego (.8), house insurance (2.4), GFC (2.2), phones (.5), melb. pollen (.03), nabu casa (.1), eweka (.1) --- noting phone is elevated presuming I also go onto Aldi plan, but that there is no family discount # annual bills - health ins (5k), rates (2.4), electricity (1.5), gas (2), internet (1.6), car insurance (.7), rego (.8), house insurance (2.4), GFC (2.2), water (1.2), eweka (.e (.7)), phones (.5), melb. pollen (.03), nabu casa (.1), eweka (.1) --- noting phone is elevated presuming I also go onto Aldi plan, but that there is no family discount
bills = 19330 bills = 21330
BUDGET=[] BUDGET=[]
BUDGET.append( ('Bills', f"${bills:,.2f}") ) BUDGET.append( ('Bills', f"${bills:,.2f}") )
BUDGET.append( ('Buffer', f"${finance_data['CBA']*finance_data['CBA_price']+finance_data['TLS']*finance_data['TLS_price']:,.2f}") ) BUDGET.append( ('Buffer', f"${finance_data['CBA']*finance_data['CBA_price']+finance_data['TLS']*finance_data['TLS_price']:,.2f}") )
@@ -308,6 +309,9 @@ def get_bill_freqs():
def new_bill( bill_type, amount, bill_date, estimated ): def new_bill( bill_type, amount, bill_date, estimated ):
conn = connect_db(False) conn = connect_db(False)
cur = conn.cursor() cur = conn.cursor()
# force delete estimates as new bill will potentially change them/growth, etc.
if not estimated:
cur.execute( f"delete from bill_data where estimated=1" )
cur.execute( f"insert into bill_data ( 'bill_type', 'amount', 'bill_date', 'estimated' ) values ( '{bill_type}', '{float(amount):.2f}', '{bill_date}', {estimated} )" ) cur.execute( f"insert into bill_data ( 'bill_type', 'amount', 'bill_date', 'estimated' ) values ( '{bill_type}', '{float(amount):.2f}', '{bill_date}', {estimated} )" )
conn.commit() conn.commit()
conn.close() conn.close()
@@ -325,7 +329,7 @@ def insert_bill_type( bt, fq ):
conn = connect_db(False) conn = connect_db(False)
cur = conn.cursor() cur = conn.cursor()
print( f"fq={fq}" ) print( f"fq={fq}" )
cur.execute( f"insert into bill_type ( 'name', 'freq', 'ann_growth_min', 'ann_growth_avg', 'ann_growth_max' ) values ( '{bt}', {fq}, 0, 0, 0 )" ) cur.execute( f"insert into bill_type ( 'name', 'freq', 'ann_growth_min', 'ann_growth_avg', 'ann_growth_max', 'ann_growth_simple' ) values ( '{bt}', {fq}, 0, 0, 0, 0 )" )
conn.commit() conn.commit()
conn.close() conn.close()
return return
@@ -354,10 +358,10 @@ def delete_bill_type( id ):
conn.close() conn.close()
return return
def set_bill_type_growth( id, min_g, avg_g, max_g ): def set_bill_type_growth( id, min_g, avg_g, max_g, simple_g ):
conn = connect_db(False) conn = connect_db(False)
cur = conn.cursor() cur = conn.cursor()
cur.execute( f"update bill_type set ann_growth_min='{min_g}', ann_growth_avg ='{avg_g}', ann_growth_max='{max_g}' where id = {id}" ) cur.execute( f"update bill_type set ann_growth_min={min_g}, ann_growth_avg ={avg_g}, ann_growth_max={max_g}, ann_growth_simple= {simple_g} where id = {id}" )
conn.commit() conn.commit()
conn.close() conn.close()
return return