v1.8.15: Abschlags-Tracker zeigt ganze Zahlungen statt Bruchmonate

Berechnung auf geleistete Abschlagszahlungen umgestellt:
Anzahl ganzer Monate seit Abrechnungsstart statt Tage/30.4.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
retr0
2026-05-05 13:12:43 +02:00
parent fec49ec4fb
commit dfb42e6902
3 changed files with 13 additions and 9 deletions
+9 -5
View File
@@ -509,17 +509,21 @@ def api_period_energy():
grundpreis = float(State.mqtt_cfg.get("grundpreis_eur_per_month", 0.0))
yr_key = history.period_key("yearly", billing_day, billing_month)
yr_start = datetime.date.fromisoformat(yr_key)
days_elapsed = (datetime.date.today() - yr_start).days
months_elapsed = round(days_elapsed / 30.4375, 4)
total_paid = round(months_elapsed * monthly_rate, 2)
grundpreis_total= round(months_elapsed * grundpreis, 2)
today = datetime.date.today()
# Anzahl geleisteter Abschlagszahlungen (ganze Monate seit Periodenstart)
months_diff = (today.year - yr_start.year) * 12 + (today.month - yr_start.month)
if today.day >= yr_start.day:
months_diff += 1
payments_made = max(0, months_diff)
total_paid = round(payments_made * monthly_rate, 2)
grundpreis_total= round(payments_made * grundpreis, 2)
energy_cost = result.get("yearly", {}).get("import_cost", 0.0)
total_cost = round(energy_cost + grundpreis_total, 2)
nachzahlung = round(total_cost - total_paid, 2)
result["billing_tracker"] = {
"monthly_rate_eur": monthly_rate,
"grundpreis_eur_per_month": grundpreis,
"months_elapsed": round(months_elapsed, 1),
"payments_made": payments_made,
"total_paid_eur": total_paid,
"grundpreis_total_eur": grundpreis_total,
"energy_cost_eur": energy_cost,