feat(деньги): валовая прибыль начислено минус себестоимость

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
anor
2026-11-10 01:43:14 +10:00
co-authored by Claude Code
parent 33c289845d
commit c4f53def0e
8 changed files with 27 additions and 11 deletions
+2 -2
View File
@@ -19,8 +19,8 @@ DASH = {"user": "boss@x", "generated_at": 1794000000, "last_visit": None,
"work_24h": {"people": 3, "requests": 20, "failures": 1, "failure_share": 0.05,
"limit_hits": 0, "latency_qa_ms": 200, "latency_qa_p95_ms": 500,
"latency_agent_ms": 3000, "latency_agent_p95_ms": 9000},
"money": {"revenue_rub": 1000, "flow_rub": 400, "accounts_total_rub": 2500,
"topups_included": True, "unpriced": 0},
"money": {"revenue_rub": 1000, "flow_rub": 400, "profit_rub": 300,
"accounts_total_rub": 2500, "topups_included": True, "unpriced": 0},
"customers": {"total": 12, "active_24h": 3},
"attention": {"failures": 1, "limit_hits": 0, "unpriced": 0}}
ATT = {"items": [{"key": "failures:24h", "severity": "high", "title": "Сбои",
+5 -3
View File
@@ -15,7 +15,7 @@ from test_admin_design_ui import browser # noqa: E402,F401
MONEY = {"period_days": 30, "revenue_rub": 1000, "refunded_rub": 0, "cost_rub": 250,
"flow_rub": 750, "charged_rub": 800, "accounts_total_rub": 2000,
"accounts_count": 2, "unpriced": 0, "topups_rub": 0}
"accounts_count": 2, "unpriced": 0, "topups_rub": 0, "profit_rub": 500}
MONTHS = [{"month": "2026-09", "revenue_rub": 500, "cost_rub": 100},
{"month": "2026-10", "revenue_rub": 500, "cost_rub": 150}]
PAYMENTS = [
@@ -97,9 +97,11 @@ def test_money_cards_charts_and_period(browser, site):
page.add_init_script("localStorage.setItem('token','t')")
page.goto(site + "/admin/v2/money")
page.wait_for_selector(".grid .card")
assert page.locator(".grid .card").count() == 4
assert page.locator(".grid .card").count() == 5
assert page.locator(".chart").count() == 2
assert "1\u00a0000" in page.locator(".grid").inner_text()
grid = page.locator(".grid").inner_text()
assert "1\u00a0000" in grid
assert "\u041f\u0440\u0438\u0431\u044b\u043b\u044c" in grid and "500" in grid
page.locator(".toolbar button", has_text="90 дней").click()
page.wait_for_timeout(500)
assert any("days=90" in c for c in Handler.calls)
+1 -1
View File
@@ -24,7 +24,7 @@ DASH = {"user": "boss@x", "generated_at": 1794000000, "last_visit": None,
"attention": {"failures": 0, "limit_hits": 0, "unpriced": 0}}
MONEY = {"period_days": 30, "revenue_rub": 100, "refunded_rub": 0, "cost_rub": 50,
"flow_rub": 50, "charged_rub": 80, "accounts_total_rub": 200,
"accounts_count": 1, "unpriced": 0, "topups_rub": 0}
"accounts_count": 1, "unpriced": 0, "topups_rub": 0, "profit_rub": 40}
# Один закрытый месяц — тот случай, на котором графики разъезжались: ширина viewBox
# зависела от числа точек, и при одной точке SVG растягивался в многоэкранную полосу.
FIN = {"months": [{"month": "2026-11", "revenue_rub": 0, "cost_rub": 714.31}], "days": 30}
+2
View File
@@ -57,6 +57,8 @@ def test_money_kopecks_and_period(env):
assert isinstance(d["revenue_kop"], int)
assert isinstance(d["flow_kop"], int) or d["flow_kop"] is None
assert d["flow_kop"] == d["revenue_kop"] - d["cost_kop"]
# Прибыль — по начислению: в этой заготовке цена клиенту 0, значит -2,50 ₽.
assert d["profit_kop"] == d["charged_kop"] - d["cost_kop"] == -250
# График по месяцам считает то же, что карточка: иначе «не сходится».
series = client.get("/api/admin/v2/finance?days=30", headers=h).json()["months"]
assert sum(m["revenue_rub"] for m in series) == pytest.approx(20.0)