финальная версия Finance Control

This commit is contained in:
2026-05-25 22:06:16 +03:00
parent 7dcb1a23a7
commit 5890e4ae64
22 changed files with 1441 additions and 927 deletions

25
app/utils/formatters.py Normal file
View File

@@ -0,0 +1,25 @@
from datetime import date, datetime
def format_money(value: float | int | None) -> str:
"""Return money value in a readable Russian format."""
amount = 0 if value is None else float(value)
return f"{amount:,.2f}".replace(",", " ")
def current_month_key() -> str:
"""Return current month in SQLite-friendly format YYYY-MM."""
return date.today().strftime("%Y-%m")
def today_text() -> str:
"""Return current date in ISO format for entry fields."""
return date.today().strftime("%Y-%m-%d")
def validate_date(value: str) -> str:
"""Validate user date and return normalized ISO date."""
try:
return datetime.strptime(value.strip(), "%Y-%m-%d").strftime("%Y-%m-%d")
except ValueError as error:
raise ValueError("Дата должна быть в формате ГГГГ-ММ-ДД.") from error