MEGAINFRA-WEBAPP/scripts/pb-show-fixed-costs.py
DEls 08ed89d9c8 feat(dashboard): enhance operations dashboard with rain outlook and coordinate support
Updated the operations dashboard to include a rain outlook feature, providing users with a 7-day forecast based on site coordinates. Added latitude and longitude fields to the site form for better weather data integration. Enhanced the fuel log and site management functionalities to utilize dynamic fuel pricing based on historical data. Improved overall data handling and user experience across various dashboard components.
2026-09-06 19:59:52 +02:00

40 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Print every fixed_costs row with its id, date and recurring flag. Read-only.
python3 scripts/pb-show-fixed-costs.py
"""
from pb_env import http, superuser_token
TOKEN = superuser_token()
code, resp = http(
"GET",
"/api/collections/fixed_costs/records?perPage=500&sort=date_logged",
token=TOKEN,
)
if code != 200:
raise SystemExit(f"could not list fixed_costs: {code} {resp}")
items = resp.get("items", [])
print(f"\n{len(items)} fixed_costs row(s):\n")
print(f" {'id':<18} {'date':<12} {'recurring':<10} {'cost':>12} description")
print(f" {'-'*18} {'-'*12} {'-'*10} {'-'*12} {'-'*30}")
total = 0.0
recurring_total = 0.0
for c in items:
cost = c.get("cost") or 0
total += cost
rec = c.get("is_recurring", "<absent>")
if rec is not False:
recurring_total += cost
print(
f" {c['id']:<18} {str(c.get('date_logged',''))[:10]:<12} "
f"{str(rec):<10} {cost:>12,.2f} {c.get('description','')[:40]}"
)
print(f"\n all rows total: {total:>12,.2f}")
print(f" recurring (is_recurring != false): {recurring_total:>12,.2f}")
months = sorted({str(c.get("date_logged", ""))[:7] for c in items if c.get("date_logged")})
print(f" months present: {months}")