fix(деньги): взносы на счёт входят в поступления, карточка сходится

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
anor
2026-11-10 01:34:29 +10:00
co-authored by Claude Code
parent bfdb7ce3d2
commit 33c289845d
9 changed files with 70 additions and 16 deletions
+21
View File
@@ -1041,6 +1041,27 @@ def list_account_entries(username: str, limit: int = 200) -> list[dict]:
return [dict(r) for r in rows]
def topups_by_month(since: float, until: float | None = None) -> dict[str, float]:
"""Ручные взносы на счёт по месяцам: пополнения минус сторно, в рублях.
Это не платежи ЮKassa, но такие же полученные деньги: в «Деньгах» кокпита они
складываются с платежами, иначе при предоплате поступления показывали ноль.
Месяцы — в поясе Хозяина, как finance_by_month."""
tail, args = "", [since]
if until is not None:
tail, args = " AND ts < ?", [since, until]
with _conn() as conn:
rows = conn.execute(
f"SELECT strftime('%Y-%m', ts, 'unixepoch', '{OWNER_TZ_SQL}') AS month, "
"COALESCE(SUM(CASE WHEN amount_kop > 0 THEN amount_kop ELSE 0 END),0) AS dep_kop, "
"COALESCE(SUM(CASE WHEN amount_kop < 0 THEN -amount_kop ELSE 0 END),0) AS cor_kop "
f"FROM account_entries WHERE ts >= ?{tail} GROUP BY month ORDER BY month",
args,
).fetchall()
return {r["month"]: (int(r["dep_kop"] or 0) - int(r["cor_kop"] or 0)) / 100
for r in rows}
def account_summary(username: str) -> dict | None:
"""Взносы человека одной строкой: {"entries", "deposited_kop", "first_ts"}; None — взносов
не было, человек не на счёте."""