Files
remnawave-bedolaga-telegram…/app/utils/formatting.py
T
Fringg c9f2dffabf fix: address 6-agent review findings for PricingEngine
H1: log error when tariff_id set but tariff relationship not loaded
H2: warn on CLASSIC_PERIOD_PRICES→PERIOD_PRICES fallback
M1: fix float division in miniapp tariff purchase (use PricingEngine.apply_discount)
M2: fix format_period Russian pluralization for teen-hundreds (111-119, etc.)
M3: deduplicate _resolve_discount_percent — import from pricing_utils
M4: fix N+1 queries in compute_simple_subscription_price (batch fetch)
M5: add period_days validation tests (negative, zero, float)
M6: add user=None tests for tariff and classic modes
M7: fix float division in calculate_prorated_price (use // instead of /)
L1: add context to _calculate_servers_price error log
L2: add comment clarifying ClassicBreakdown.group_discount_pct type
L3: add test for original_total property
L4: inline _apply_percentage_discount wrapper in subscription_purchase_service
L5: replace global _server_id_counter with itertools.count() in tests
2026-03-13 05:45:46 +03:00

35 lines
988 B
Python

"""Shared formatting utilities for traffic, price, and period display."""
def format_traffic(gb: int) -> str:
"""Форматирует трафик."""
if gb == 0:
return 'Безлимит'
return f'{gb} ГБ'
def format_price_kopeks(kopeks: int, compact: bool = False) -> str:
"""Форматирует цену из копеек в рубли."""
rubles = kopeks / 100
if compact:
# Компактный формат - округляем до рублей
return f'{int(round(rubles))}'
if rubles == int(rubles):
return f'{int(rubles)}'
return f'{rubles:.2f}'
def format_period(days: int) -> str:
"""Форматирует период."""
mod100 = days % 100
mod10 = days % 10
if 11 <= mod100 <= 19:
word = 'дней'
elif mod10 == 1:
word = 'день'
elif 2 <= mod10 <= 4:
word = 'дня'
else:
word = 'дней'
return f'{days} {word}'