41 lines
1.2 KiB
Python
41 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}")
|