add a button to recalc bills by removing all esimated bills and rebuild them

This commit is contained in:
2025-10-17 21:22:07 +11:00
parent bf66e9fa7c
commit 227e95cab7
3 changed files with 22 additions and 2 deletions

9
db.py
View File

@@ -395,3 +395,12 @@ def save_ui(data):
conn.commit() conn.commit()
conn.close() conn.close()
return return
def delete_estimated_bills():
conn = connect_db(False)
cur = conn.cursor()
cur.execute( "delete from bill_data where estimated=1" )
conn.commit()
conn.close()
return

View File

@@ -2,7 +2,7 @@
from flask import Flask, render_template, request, redirect, url_for, Response, jsonify from flask import Flask, render_template, request, redirect, url_for, Response, jsonify
from calc import calculate_savings_depletion, calc_key_dates 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 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_data, new_bill, update_bill_data, delete_bill, delete_estimated_bills
from db import get_bill_ui, save_ui 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 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 from bills import process_bill_data, calc_future_totals, set_bill_type_growth
@@ -142,6 +142,7 @@ def update():
request.form['Ioniq6_future'] request.form['Ioniq6_future']
) )
update_finance(finance_data) update_finance(finance_data)
# FIXME: need code here to delete/rebuild future bills if we change "D # Pays to quit "
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route('/bills') @app.route('/bills')
@@ -214,6 +215,10 @@ def SaveUI():
save_ui( data ) save_ui( data )
return "200" return "200"
@app.route('/force_recalc_bills', methods=['POST'])
def force_recalc_bills():
delete_estimated_bills()
return "200"
# Main program # Main program
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -52,6 +52,7 @@
</div> </div>
<button id="save-bill-type" class="new-bill-type-class px-0 col-1 btn btn-success bg-success-subtle text-success d-none" onClick="NewBillType()"><span class="bi bi-floppy"></span> Save</button> <button id="save-bill-type" class="new-bill-type-class px-0 col-1 btn btn-success bg-success-subtle text-success d-none" onClick="NewBillType()"><span class="bi bi-floppy"></span> Save</button>
<button id="canc-bill-type" class="new-bill-type-class px-0 col-1 btn btn-danger bg-danger-subtle text-danger d-none" onClick="CancelNewBillType()"><span class="bi bi-x"> Cancel</span></button> <button id="canc-bill-type" class="new-bill-type-class px-0 col-1 btn btn-danger bg-danger-subtle text-danger d-none" onClick="CancelNewBillType()"><span class="bi bi-x"> Cancel</span></button>
<button id="recalc-bills" class="mt-4 col-2 offset-3 btn btn-warning bg-warning-subtle text-warning" onClick="ForceRecalcBills()"><span class="bi bi-repeat"> Recalculate</span></button>
</div> </div>
<div class="row"> <div class="row">
<div class="px-0 col-2"><label class="form-control text-center border-0 fw-bold bg-body-tertiary rounded-0">Name</ ></div> <div class="px-0 col-2"><label class="form-control text-center border-0 fw-bold bg-body-tertiary rounded-0">Name</ ></div>
@@ -131,7 +132,7 @@
<!-- right-hand-side, bill types (e.g. gas, phone, etc.) --> <!-- right-hand-side, bill types (e.g. gas, phone, etc.) -->
<div class="pt-4 col-5"> <div class="col-5">
<div class="row"> <div class="row">
<div class="col-2 form-control-inline d-none new-bill-data-class">Bill Type</div> <div class="col-2 form-control-inline d-none new-bill-data-class">Bill Type</div>
<div id="new-bill-data-date-label" class="col-4 form-control-inline d-none new-bill-data-class">Date</div> <div id="new-bill-data-date-label" class="col-4 form-control-inline d-none new-bill-data-class">Date</div>
@@ -466,6 +467,11 @@
}); });
}); });
function ForceRecalcBills()
{
$.ajax( { type: 'POST', url: '/force_recalc_bills', contentType: 'application/json', success: function() { window.location='bills' } } )
}
</script> </script>
</body> </body>
</html> </html>