- расчёт ведётся в базовой валюте модели: баланс счёта переводится из валюты счёта, операция — из своей валюты (пусто = валюта счёта), актив и обязательство — из своей (пусто = базовая); - нет курса — не падение, а предупреждение: сумма не попадает в прогноз, но пользователь видит, чего не хватает (нет курса USD → RUB); - FinancialModel.display_currency — валюта вывода по умолчанию; новая команда cf config display-currency; cf forecast/scenario/compare печатают предупреждения расчёта; cf info показывает обе валюты и суммы в валюте их владельца; - рост активов при нулевых балансах теперь делится поровну — раньше он делился по доле от единицы и просто исчезал. Тесты: 296 → 302 (класс TestForecastCurrency: конвертация баланса, операции, актива, регулярного платежа, предупреждение об отсутствии курса).
98 lines
4.8 KiB
Python
98 lines
4.8 KiB
Python
"""cf info — сводка всей финансовой модели."""
|
|
|
|
from rich.table import Table
|
|
|
|
from domain import CurrencyConverter
|
|
from infrastructure.cli.services import console, load_model
|
|
from infrastructure.i18n import t
|
|
|
|
|
|
def info() -> None:
|
|
"""Сводка всей финансовой модели"""
|
|
model = load_model()
|
|
converter = CurrencyConverter(model.exchange_rates)
|
|
symbol = converter.get_symbol(model.base_currency)
|
|
|
|
console.print(f"[bold]{t('cmd.info.metadata')}[/bold]")
|
|
console.print(f" {t('cmd.info.base_currency', currency=model.base_currency, symbol=symbol)}")
|
|
output_symbol = converter.get_symbol(model.output_currency)
|
|
console.print(f" {t('cmd.info.display_currency', currency=model.output_currency, symbol=output_symbol)}")
|
|
console.print(f" {t('cmd.info.accounts', count=len(model.accounts))}")
|
|
console.print(f" {t('cmd.info.transactions', count=len(model.transactions))}")
|
|
console.print(f" {t('cmd.info.recurring', count=len(model.recurring))}")
|
|
console.print(f" {t('cmd.info.assets', count=len(model.assets))}")
|
|
console.print(f" {t('cmd.info.liabilities', count=len(model.liabilities))}")
|
|
console.print(f" {t('cmd.info.rates', count=len(model.exchange_rates))}")
|
|
|
|
if model.accounts:
|
|
tbl = Table(title=t("table.accounts.title"))
|
|
tbl.add_column(t("table.accounts.col.name"), style="cyan")
|
|
tbl.add_column(t("table.accounts.col.currency"))
|
|
tbl.add_column(t("table.accounts.col.balance"), justify="right")
|
|
for a in model.accounts:
|
|
currency = a.currency or model.base_currency
|
|
tbl.add_row(a.name, currency, CurrencyConverter.format_money(a.balance, currency))
|
|
console.print(tbl)
|
|
|
|
if model.transactions:
|
|
tbl = Table(title=t("table.transactions.title"))
|
|
tbl.add_column(t("table.transactions.col.date"))
|
|
tbl.add_column(t("table.transactions.col.category"))
|
|
tbl.add_column(t("table.transactions.col.amount"), justify="right")
|
|
tbl.add_column(t("table.transactions.col.description"))
|
|
for tx in model.transactions[:10]:
|
|
currency = tx.currency or _account_currency(model, tx.account) or model.base_currency
|
|
amount_str = CurrencyConverter.format_money(tx.amount, currency)
|
|
tbl.add_row(tx.date, tx.category, amount_str, tx.description)
|
|
if len(model.transactions) > 10:
|
|
console.print(tbl)
|
|
console.print(t("cmd.info.more", count=len(model.transactions) - 10))
|
|
else:
|
|
console.print(tbl)
|
|
|
|
if model.recurring:
|
|
tbl = Table(title=t("table.recurring.title"))
|
|
tbl.add_column(t("table.recurring.col.period"))
|
|
tbl.add_column(t("table.recurring.col.amount"), justify="right")
|
|
tbl.add_column(t("table.recurring.col.category"))
|
|
for r in model.recurring:
|
|
currency = r.currency or _account_currency(model, r.account) or model.base_currency
|
|
amount_str = CurrencyConverter.format_money(r.amount, currency)
|
|
tbl.add_row(r.frequency, amount_str, r.category)
|
|
console.print(tbl)
|
|
|
|
if model.assets:
|
|
tbl = Table(title=t("table.assets.title"))
|
|
tbl.add_column(t("table.assets.col.name"), style="cyan")
|
|
tbl.add_column(t("table.assets.col.value"), justify="right")
|
|
tbl.add_column(t("table.assets.col.growth"), justify="right")
|
|
for a in model.assets:
|
|
currency = a.currency or model.base_currency
|
|
value_str = CurrencyConverter.format_money(a.value, currency)
|
|
tbl.add_row(a.name, value_str, f"{a.growth_rate:.1f}%")
|
|
console.print(tbl)
|
|
|
|
if model.liabilities:
|
|
tbl = Table(title=t("table.liabilities.title"))
|
|
tbl.add_column(t("table.liabilities.col.name"), style="cyan")
|
|
tbl.add_column(t("table.liabilities.col.balance"), justify="right")
|
|
tbl.add_column(t("table.liabilities.col.rate"), justify="right")
|
|
tbl.add_column(t("table.liabilities.col.payment"), justify="right")
|
|
for li in model.liabilities:
|
|
currency = li.currency or model.base_currency
|
|
balance_str = CurrencyConverter.format_money(li.balance, currency)
|
|
payment_str = CurrencyConverter.format_money(li.payment, currency)
|
|
tbl.add_row(li.name, balance_str, f"{li.interest:.1f}%", payment_str)
|
|
console.print(tbl)
|
|
|
|
|
|
def _account_currency(model, reference: str) -> str:
|
|
"""Валюта счёта по ссылке (UUID или имя). Пусто — счёт не найден."""
|
|
value = (reference or "").strip()
|
|
if not value:
|
|
return ""
|
|
for account in model.accounts:
|
|
if value == str(account.id) or value.casefold() == account.name.strip().casefold():
|
|
return account.currency or model.base_currency
|
|
return ""
|