chore: baseline before agreements

This commit is contained in:
Александр Арсентьев
2026-09-25 17:53:33 +03:00
commit 2376778828
37 changed files with 2870 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
from decimal import Decimal, InvalidOperation, ROUND_HALF_UP
def format_money(value, currency="RUB"):
"""Format a monetary value for display without changing stored/calculated values."""
try:
amount = Decimal(str(value if value is not None else 0))
amount = amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
except (InvalidOperation, ValueError, TypeError):
amount = Decimal("0.00")
# Python's grouping is 1,234.56; convert it to Russian UI separators.
formatted = f"{amount:,.2f}".replace(",", "\0").replace(".", ",").replace("\0", " ")
currency = (currency or "RUB").strip()
if currency.upper() == "RUB":
return f"{formatted} ₽"
return f"{formatted} {currency}"