From 2937866617881a05d65cac04e6bf717793a291de Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sun, 31 Aug 2025 10:24:46 +1000 Subject: [PATCH] improve how we find monthly bill in a month, dont use exact date just use yy-mm, also fix BUG where kayo used estimate in jan to project for the next 5years, rather than real bill in feb (all in the future) to estimate --- BUGS | 1 - bills.py | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/BUGS b/BUGS index 03f4bae..bc5466e 100644 --- a/BUGS +++ b/BUGS @@ -1,4 +1,3 @@ -* kayo is using wrong bill to extend - there is a future bill in the monthly and that is not being used... * added an electricity bill by accident for 2018, that kills lots :( - something to do with missing year of data in quarterly bills - still an issue diff --git a/bills.py b/bills.py index bd7c379..79fea32 100644 --- a/bills.py +++ b/bills.py @@ -110,6 +110,10 @@ def find_previous_bill( bill_type, bill_info, bill_date ): # okay, we have the previous billing year, and we wanted one for a year in the future, # just return the last one in this year as its the most recent if wanted_year > yr: + # small chance of future bills having estimates and reals (kayo did this) + for tmp in bill_info[bill_type]['year'][yr]: + if tmp['estimated'] == 0: + return tmp return bill_info[bill_type]['year'][yr][0] else: # lets go through the newest to oldest of these bills @@ -219,12 +223,13 @@ def add_missing_monthly_bills_in_yr( bill_type, bill_info, yr ): for i in range( start_m+1, 13 ): bill_found=False new_date = f'{yr}-{i:02d}-{dd}' + new_date_yymm=f'{yr}-{i:02d}' if yr in bill_info[bill_type]['year']: for b in bill_info[bill_type]['year'][yr]: # this bill exists, skip adding it (this occurs when called to # add bills as there are < 12 bills in first_year, BUT, we # don't fill before first_bill so the < 12 ALWAYS triggers - if str(b['bill_date']) == new_date: + if new_date_yymm in str(b['bill_date']): bill_found=True break if not bill_found: