fix(деньги): округление один раз

This commit is contained in:
anor
2026-11-06 22:30:28 +10:00
parent 7ad2368719
commit e4d2c9601b
4 changed files with 37 additions and 13 deletions
+13 -7
View File
@@ -25,13 +25,18 @@ def summary(now: float | None = None, days: int = 30) -> dict:
import balance
import billing
months = finance_by_month(now - days * 86400)["months"]
revenue = round(sum(m["revenue_rub"] for m in months), 2)
refunded = round(sum(m["refunded_rub"] for m in months), 2)
months = finance_by_month(now - days * 86400, round_kop=False)["months"]
# Суммы — сырые; копейки округляем ОДИН раз, а не каждый месяц до сводки.
revenue_raw = sum(m["revenue_rub"] for m in months)
refunded_raw = sum(m["refunded_rub"] for m in months)
costs = [m["cost_rub"] for m in months if m["cost_rub"] is not None]
cost = round(sum(costs), 2) if costs else None
flow = round(revenue - cost, 2) if cost is not None else None
charged = round(sum(m["price_rub"] or 0 for m in months), 2)
cost_raw = sum(costs) if costs else None
charged_raw = sum(m["price_rub"] or 0 for m in months)
revenue = round(revenue_raw, 2)
refunded = round(refunded_raw, 2)
cost = round(cost_raw, 2) if cost_raw is not None else None
flow = round(revenue_raw - cost_raw, 2) if cost_raw is not None else None
charged = round(charged_raw, 2)
try:
accounts = account_balances_all()
rows = [balance.compose(a["deposited_kop"], a["charged"], a["first_ts"], a["unpriced"])
@@ -46,7 +51,8 @@ def summary(now: float | None = None, days: int = 30) -> dict:
rows = []
accounts_kop = (sum(int(r.get("balance_kop") or _kop(r.get("balance_rub")) or 0)
for r in rows) if accounts_total is not None else None)
revenue_kop, cost_kop = _kop(revenue), _kop(cost)
revenue_kop = _kop(revenue_raw)
cost_kop = _kop(cost_raw) if cost_raw is not None else None
flow_kop = (revenue_kop - cost_kop
if revenue_kop is not None and cost_kop is not None else None)
return {"period_days": days,