feat(api): Core-API mit Authentifizierung, CRUD und Monatsreport
- Anmeldung über Argon2id und JWT in httpOnly-Cookies, Refresh mit echter Rotation über die neue Tabelle refresh_token - AuthProvider-Protokoll als Vorbereitung für OIDC, Administrator-Anlage beim Erststart mit erzwungenem Passwortwechsel - CRUD für Konten, Kategorien (zweistufiger Baum), Firmen, Recurrences, Preisversionen, Buchungen, Budgets, Vorlagen und Sparziele - Fälligkeiten mit Overlay-Logik: abrufen, bestätigen, auslassen, zurücksetzen - Kontosalden zum Stichtag, Monatsübersicht mit Plan-Ist-Vergleich - SECRET_KEY jetzt mindestens 32 Zeichen; Platzhalter in Produktion abgelehnt - 61 neue Integrationstests, insgesamt 148 grün Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014e7t8UpmoVNMtWivY5LiSH
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
"""Schemata für Konten."""
|
||||
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.models.enums import AccountType
|
||||
from app.schemas.common import ApiModel, HexColor, InputModel, Money
|
||||
|
||||
|
||||
class AccountBase(InputModel):
|
||||
name: str = Field(min_length=1, max_length=120, examples=["Girokonto"])
|
||||
type: AccountType = AccountType.CHECKING
|
||||
iban_last4: str | None = Field(
|
||||
default=None, pattern=r"^\d{4}$", description="Letzte vier Stellen der IBAN."
|
||||
)
|
||||
opening_balance: Money = Field(
|
||||
default=Decimal("0.00"), description="Saldo zum Stichtag `opening_balance_date`."
|
||||
)
|
||||
opening_balance_date: date
|
||||
color: HexColor = "#3b82f6"
|
||||
icon: str = Field(default="wallet", max_length=64, description="Name eines lucide-Icons.")
|
||||
is_active: bool = True
|
||||
sort_order: int = 0
|
||||
|
||||
|
||||
class AccountCreate(AccountBase):
|
||||
pass
|
||||
|
||||
|
||||
class AccountUpdate(InputModel):
|
||||
"""Alle Felder optional – gesetzt wird nur, was mitgeschickt wurde."""
|
||||
|
||||
name: str | None = Field(default=None, min_length=1, max_length=120)
|
||||
type: AccountType | None = None
|
||||
iban_last4: str | None = Field(default=None, pattern=r"^\d{4}$")
|
||||
opening_balance: Money | None = None
|
||||
opening_balance_date: date | None = None
|
||||
color: HexColor | None = None
|
||||
icon: str | None = Field(default=None, max_length=64)
|
||||
is_active: bool | None = None
|
||||
sort_order: int | None = None
|
||||
|
||||
|
||||
class AccountOut(ApiModel):
|
||||
id: int
|
||||
name: str
|
||||
type: AccountType
|
||||
iban_last4: str | None
|
||||
opening_balance: Money
|
||||
opening_balance_date: date
|
||||
color: str
|
||||
icon: str
|
||||
is_active: bool
|
||||
sort_order: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class AccountBalanceOut(ApiModel):
|
||||
"""Fortgeschriebener Saldo zu einem Stichtag."""
|
||||
|
||||
account_id: int
|
||||
as_of: date
|
||||
opening_balance: Money
|
||||
booked_transactions: Money = Field(description="Summe der einmaligen Buchungen.")
|
||||
booked_occurrences: Money = Field(description="Summe der bestätigten Fälligkeiten.")
|
||||
balance: Money = Field(description="Eröffnungssaldo zuzüglich aller Bewegungen.")
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Schemata für Anmeldung und Benutzerkonto."""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.schemas.common import ApiModel, InputModel
|
||||
|
||||
|
||||
class LoginRequest(InputModel):
|
||||
username: str = Field(min_length=1, max_length=120, examples=["admin"])
|
||||
password: str = Field(min_length=1, max_length=256)
|
||||
|
||||
|
||||
class ChangePasswordRequest(InputModel):
|
||||
current_password: str = Field(min_length=1, max_length=256)
|
||||
new_password: str = Field(min_length=10, max_length=256)
|
||||
|
||||
|
||||
class UserOut(ApiModel):
|
||||
"""Der angemeldete Benutzer."""
|
||||
|
||||
id: int
|
||||
username: str
|
||||
email: str | None = None
|
||||
must_change_password: bool = Field(
|
||||
description="Solange true, sind außer /api/me und /api/auth/* alle Routen gesperrt."
|
||||
)
|
||||
last_login_at: datetime | None = None
|
||||
@@ -0,0 +1,120 @@
|
||||
"""Schemata für Budgets, Budgetvorlagen und Sparziele."""
|
||||
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
|
||||
from app.schemas.common import (
|
||||
ApiModel,
|
||||
HexColor,
|
||||
InputModel,
|
||||
Money,
|
||||
NonNegativeMoney,
|
||||
PositiveMoney,
|
||||
)
|
||||
|
||||
|
||||
def _to_month_start(value: date) -> date:
|
||||
"""Budgets gelten immer für einen ganzen Monat."""
|
||||
return value.replace(day=1)
|
||||
|
||||
|
||||
class BudgetCreate(InputModel):
|
||||
category_id: int
|
||||
period_month: date = Field(description="Beliebiger Tag im Monat; wird auf den Ersten gesetzt.")
|
||||
limit_amount: PositiveMoney
|
||||
rollover: bool = Field(
|
||||
default=False, description="Nicht verbrauchtes Budget in den Folgemonat übernehmen."
|
||||
)
|
||||
|
||||
@field_validator("period_month")
|
||||
@classmethod
|
||||
def _normalise(cls, value: date) -> date:
|
||||
return _to_month_start(value)
|
||||
|
||||
|
||||
class BudgetUpdate(InputModel):
|
||||
limit_amount: PositiveMoney | None = None
|
||||
rollover: bool | None = None
|
||||
|
||||
|
||||
class BudgetOut(ApiModel):
|
||||
id: int
|
||||
category_id: int
|
||||
period_month: date
|
||||
limit_amount: Money
|
||||
rollover: bool
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class BudgetTemplateCreate(InputModel):
|
||||
category_id: int
|
||||
valid_from: date = Field(description="Ab diesem Monat gilt die Vorlage dauerhaft.")
|
||||
valid_until: date | None = Field(default=None, description="Letzter Monat, sonst unbegrenzt.")
|
||||
limit_amount: PositiveMoney
|
||||
rollover: bool = False
|
||||
|
||||
@field_validator("valid_from", "valid_until")
|
||||
@classmethod
|
||||
def _normalise(cls, value: date | None) -> date | None:
|
||||
return _to_month_start(value) if value else None
|
||||
|
||||
|
||||
class BudgetTemplateUpdate(InputModel):
|
||||
valid_until: date | None = None
|
||||
limit_amount: PositiveMoney | None = None
|
||||
rollover: bool | None = None
|
||||
|
||||
@field_validator("valid_until")
|
||||
@classmethod
|
||||
def _normalise(cls, value: date | None) -> date | None:
|
||||
return _to_month_start(value) if value else None
|
||||
|
||||
|
||||
class BudgetTemplateOut(ApiModel):
|
||||
id: int
|
||||
category_id: int
|
||||
valid_from: date
|
||||
valid_until: date | None
|
||||
limit_amount: Money
|
||||
rollover: bool
|
||||
|
||||
|
||||
class SavingsGoalCreate(InputModel):
|
||||
name: str = Field(min_length=1, max_length=160, examples=["Neues Fahrrad"])
|
||||
target_amount: PositiveMoney
|
||||
target_date: date | None = None
|
||||
current_amount: NonNegativeMoney = Decimal("0.00")
|
||||
account_id: int | None = None
|
||||
monthly_contribution: PositiveMoney | None = None
|
||||
color: HexColor = "#10b981"
|
||||
icon: str = Field(default="piggy-bank", max_length=64)
|
||||
is_archived: bool = False
|
||||
|
||||
|
||||
class SavingsGoalUpdate(InputModel):
|
||||
name: str | None = Field(default=None, min_length=1, max_length=160)
|
||||
target_amount: PositiveMoney | None = None
|
||||
target_date: date | None = None
|
||||
current_amount: NonNegativeMoney | None = None
|
||||
account_id: int | None = None
|
||||
monthly_contribution: PositiveMoney | None = None
|
||||
color: HexColor | None = None
|
||||
icon: str | None = Field(default=None, max_length=64)
|
||||
is_archived: bool | None = None
|
||||
|
||||
|
||||
class SavingsGoalOut(ApiModel):
|
||||
id: int
|
||||
name: str
|
||||
target_amount: Money
|
||||
target_date: date | None
|
||||
current_amount: Money
|
||||
account_id: int | None
|
||||
monthly_contribution: Money | None
|
||||
color: str
|
||||
icon: str
|
||||
is_archived: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
@@ -0,0 +1,49 @@
|
||||
"""Schemata für den zweistufigen Kategoriebaum."""
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.models.enums import EntryKind
|
||||
from app.schemas.common import ApiModel, HexColor, InputModel
|
||||
|
||||
|
||||
class CategoryCreate(InputModel):
|
||||
name: str = Field(min_length=1, max_length=120, examples=["Streaming"])
|
||||
kind: EntryKind = Field(description="Wird bei Unterkategorien vom Elternknoten übernommen.")
|
||||
parent_id: int | None = Field(
|
||||
default=None, description="Nur Oberkategorien zulässig – der Baum ist zweistufig."
|
||||
)
|
||||
color: HexColor = "#64748b"
|
||||
icon: str = Field(default="circle", max_length=64)
|
||||
is_fixed_cost: bool = Field(
|
||||
default=False, description="Zählt in die Kennzahl 'Verfügbar nach Fixkosten'."
|
||||
)
|
||||
sort_order: int = 0
|
||||
is_archived: bool = False
|
||||
|
||||
|
||||
class CategoryUpdate(InputModel):
|
||||
name: str | None = Field(default=None, min_length=1, max_length=120)
|
||||
parent_id: int | None = None
|
||||
color: HexColor | None = None
|
||||
icon: str | None = Field(default=None, max_length=64)
|
||||
is_fixed_cost: bool | None = None
|
||||
sort_order: int | None = None
|
||||
is_archived: bool | None = None
|
||||
|
||||
|
||||
class CategoryOut(ApiModel):
|
||||
id: int
|
||||
parent_id: int | None
|
||||
name: str
|
||||
kind: EntryKind
|
||||
color: str
|
||||
icon: str
|
||||
is_fixed_cost: bool
|
||||
sort_order: int
|
||||
is_archived: bool
|
||||
|
||||
|
||||
class CategoryTreeOut(CategoryOut):
|
||||
"""Oberkategorie mit ihren Unterkategorien."""
|
||||
|
||||
children: list[CategoryOut] = Field(default_factory=list)
|
||||
@@ -0,0 +1,55 @@
|
||||
"""Gemeinsame Bausteine aller API-Schemata."""
|
||||
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
# Geldbeträge werden als Decimal geführt und im JSON als String ausgeliefert,
|
||||
# damit auf dem Weg zum Frontend keine Genauigkeit verloren geht.
|
||||
Money = Annotated[Decimal, Field(max_digits=12, decimal_places=2)]
|
||||
PositiveMoney = Annotated[Decimal, Field(gt=0, max_digits=12, decimal_places=2)]
|
||||
NonNegativeMoney = Annotated[Decimal, Field(ge=0, max_digits=12, decimal_places=2)]
|
||||
HexColor = Annotated[str, Field(pattern=r"^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$")]
|
||||
|
||||
|
||||
class ApiModel(BaseModel):
|
||||
"""Basisklasse für Ausgabeschemata; liest Werte direkt von ORM-Objekten."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class InputModel(BaseModel):
|
||||
"""Basisklasse für Eingabeschemata; unbekannte Felder werden abgewiesen."""
|
||||
|
||||
model_config = ConfigDict(extra="forbid", str_strip_whitespace=True)
|
||||
|
||||
|
||||
class Page[T](ApiModel):
|
||||
"""Einfache Seitenausgabe mit Gesamtzahl."""
|
||||
|
||||
items: list[T]
|
||||
total: int = Field(description="Gesamtzahl der Treffer ohne Berücksichtigung der Seite.")
|
||||
limit: int
|
||||
offset: int
|
||||
|
||||
|
||||
class DateRange(InputModel):
|
||||
"""Ein von/bis-Zeitraum, beide Grenzen einschließlich."""
|
||||
|
||||
date_from: date
|
||||
date_to: date
|
||||
|
||||
|
||||
class ErrorResponse(BaseModel):
|
||||
"""Einheitliches Fehlerformat aller Endpunkte."""
|
||||
|
||||
detail: str = Field(description="Für Menschen lesbare Beschreibung des Fehlers.")
|
||||
code: str = Field(description="Stabiler Fehlercode zur Auswertung im Frontend.")
|
||||
|
||||
|
||||
class MessageResponse(BaseModel):
|
||||
"""Antwort für Aktionen ohne eigene Nutzlast."""
|
||||
|
||||
detail: str
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Schemata für Firmen und Zahlungsempfänger."""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.models.enums import LogoSource, LogoStatus
|
||||
from app.schemas.common import ApiModel, HexColor, InputModel
|
||||
|
||||
|
||||
class MerchantCreate(InputModel):
|
||||
name: str = Field(min_length=1, max_length=160, examples=["Netflix"])
|
||||
domain: str | None = Field(
|
||||
default=None,
|
||||
max_length=255,
|
||||
examples=["netflix.com"],
|
||||
description="Verbessert die Trefferquote der Logosuche erheblich.",
|
||||
)
|
||||
aliases: list[str] = Field(
|
||||
default_factory=list, description="Weitere Schreibweisen, etwa aus Kontoauszügen."
|
||||
)
|
||||
brand_color: HexColor | None = None
|
||||
brand_color_dark: HexColor | None = None
|
||||
|
||||
|
||||
class MerchantUpdate(InputModel):
|
||||
name: str | None = Field(default=None, min_length=1, max_length=160)
|
||||
domain: str | None = Field(default=None, max_length=255)
|
||||
aliases: list[str] | None = None
|
||||
brand_color: HexColor | None = None
|
||||
brand_color_dark: HexColor | None = None
|
||||
|
||||
|
||||
class MerchantOut(ApiModel):
|
||||
id: int
|
||||
name: str
|
||||
normalized_name: str
|
||||
domain: str | None
|
||||
aliases: list[str]
|
||||
logo_asset_id: int | None = Field(
|
||||
description="Wenn gesetzt, ist das Logo unter /api/logos/{id} abrufbar."
|
||||
)
|
||||
brand_color: str | None
|
||||
brand_color_dark: str | None
|
||||
logo_source: LogoSource | None
|
||||
logo_status: LogoStatus
|
||||
created_at: datetime
|
||||
@@ -0,0 +1,64 @@
|
||||
"""Schemata für einzelne Fälligkeiten."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.models.enums import EntryKind, OccurrenceStatus
|
||||
from app.schemas.common import ApiModel, InputModel, Money, PositiveMoney
|
||||
|
||||
|
||||
class OccurrenceOut(ApiModel):
|
||||
"""Eine berechnete Fälligkeit, ggf. überlagert von einer materialisierten Zeile."""
|
||||
|
||||
recurrence_id: int
|
||||
recurrence_title: str
|
||||
kind: EntryKind
|
||||
category_id: int
|
||||
merchant_id: int | None
|
||||
account_id: int | None
|
||||
nominal_date: date = Field(
|
||||
description="Von der Wiederholungsregel geliefertes Datum. Schlüssel für "
|
||||
"`confirm` und `skip`, auch wenn der Zahltag verschoben ist."
|
||||
)
|
||||
due_date: date = Field(description="Zahltag nach Wochenend- und Feiertagsverschiebung.")
|
||||
effective_date: date = Field(description="Ist-Datum, sonst der Zahltag.")
|
||||
amount: Money = Field(description="Sollbetrag laut Preishistorie.")
|
||||
actual_amount: Money | None = None
|
||||
effective_amount: Money = Field(description="Ist-Betrag, sonst Soll. Ausgelassene zählen 0.")
|
||||
status: OccurrenceStatus
|
||||
is_variable: bool
|
||||
occurrence_id: int | None = None
|
||||
note: str | None = None
|
||||
installment_number: int | None = None
|
||||
installments_total: int | None = None
|
||||
|
||||
|
||||
class OccurrenceConfirm(InputModel):
|
||||
"""Bestätigt eine Fälligkeit, wahlweise mit abweichendem Betrag oder Datum."""
|
||||
|
||||
recurrence_id: int
|
||||
occurrence_date: date = Field(description="Das nominale Datum aus `OccurrenceOut`.")
|
||||
actual_amount: PositiveMoney | None = Field(
|
||||
default=None, description="Ohne Angabe gilt der Sollbetrag."
|
||||
)
|
||||
actual_date: date | None = Field(
|
||||
default=None, description="Ohne Angabe gilt der berechnete Zahltag."
|
||||
)
|
||||
account_id: int | None = Field(default=None, description="Abweichendes Konto.")
|
||||
note: str | None = None
|
||||
|
||||
|
||||
class OccurrenceSkip(InputModel):
|
||||
"""Markiert eine Fälligkeit als ausgefallen; sie zählt danach nirgends mehr mit."""
|
||||
|
||||
recurrence_id: int
|
||||
occurrence_date: date
|
||||
note: str | None = None
|
||||
|
||||
|
||||
class OccurrenceReset(InputModel):
|
||||
"""Nimmt eine Bestätigung oder Auslassung zurück."""
|
||||
|
||||
recurrence_id: int
|
||||
occurrence_date: date
|
||||
@@ -0,0 +1,183 @@
|
||||
"""Schemata für wiederkehrende Posten, Preisversionen und Vorschau."""
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
|
||||
from app.models.enums import BusinessDayShift, EntryKind
|
||||
from app.schemas.common import ApiModel, InputModel, Money, PositiveMoney
|
||||
from app.schemas.merchant import MerchantOut
|
||||
from app.services.recurrence import InvalidRRuleError, validate_rrule
|
||||
|
||||
|
||||
class RecurrenceBase(InputModel):
|
||||
kind: EntryKind
|
||||
title: str = Field(min_length=1, max_length=160, examples=["Netflix Standard"])
|
||||
merchant_id: int | None = None
|
||||
category_id: int
|
||||
account_id: int
|
||||
amount: PositiveMoney = Field(
|
||||
description="Aktueller Betrag. Immer positiv – die Richtung steckt in `kind`."
|
||||
)
|
||||
is_variable: bool = Field(
|
||||
default=False, description="Geschätzter Betrag, das Ist weicht regelmäßig ab."
|
||||
)
|
||||
currency: str = Field(default="EUR", pattern=r"^[A-Z]{3}$")
|
||||
|
||||
rrule: str = Field(
|
||||
max_length=500,
|
||||
examples=["FREQ=MONTHLY;BYMONTHDAY=1"],
|
||||
description="Vollständige RFC-5545-RRULE ohne DTSTART.",
|
||||
)
|
||||
dtstart: date = Field(description="Erste mögliche Fälligkeit der Serie.")
|
||||
until: date | None = Field(default=None, description="Hartes Serienende, einschließlich.")
|
||||
|
||||
business_day_shift: BusinessDayShift = Field(
|
||||
default=BusinessDayShift.NEXT,
|
||||
description="Verschiebung, wenn der Termin auf Wochenende oder Feiertag fällt.",
|
||||
)
|
||||
holiday_region: str = Field(default="DE-NW", max_length=8, examples=["DE-NW"])
|
||||
|
||||
installments_total: int | None = Field(
|
||||
default=None, ge=1, description="Anzahl Raten; beendet die Serie unabhängig von der RRULE."
|
||||
)
|
||||
principal_amount: PositiveMoney | None = Field(
|
||||
default=None, description="Ursprüngliche Darlehenssumme für die Restschuldberechnung."
|
||||
)
|
||||
|
||||
contract_start: date | None = None
|
||||
contract_min_term_months: int | None = Field(default=None, ge=1)
|
||||
contract_notice_period_days: int | None = Field(default=None, ge=0)
|
||||
contract_auto_renew_months: int | None = Field(default=None, ge=1)
|
||||
|
||||
reserve_enabled: bool = Field(
|
||||
default=False, description="Bildet monatliche Rücklagen für nicht-monatliche Posten."
|
||||
)
|
||||
notes: str | None = None
|
||||
tags: list[str] = Field(default_factory=list)
|
||||
is_active: bool = True
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _check_rule_and_dates(self) -> "RecurrenceBase":
|
||||
try:
|
||||
validate_rrule(self.rrule, self.dtstart)
|
||||
except InvalidRRuleError as exc:
|
||||
raise ValueError(str(exc)) from exc
|
||||
if self.until is not None and self.until < self.dtstart:
|
||||
raise ValueError("Das Serienende darf nicht vor dem Start liegen.")
|
||||
return self
|
||||
|
||||
|
||||
class RecurrenceCreate(RecurrenceBase):
|
||||
pass
|
||||
|
||||
|
||||
class RecurrenceUpdate(InputModel):
|
||||
"""Alle Felder optional. RRULE und `dtstart` werden zusammen geprüft."""
|
||||
|
||||
kind: EntryKind | None = None
|
||||
title: str | None = Field(default=None, min_length=1, max_length=160)
|
||||
merchant_id: int | None = None
|
||||
category_id: int | None = None
|
||||
account_id: int | None = None
|
||||
amount: PositiveMoney | None = None
|
||||
is_variable: bool | None = None
|
||||
currency: str | None = Field(default=None, pattern=r"^[A-Z]{3}$")
|
||||
rrule: str | None = Field(default=None, max_length=500)
|
||||
dtstart: date | None = None
|
||||
until: date | None = None
|
||||
business_day_shift: BusinessDayShift | None = None
|
||||
holiday_region: str | None = Field(default=None, max_length=8)
|
||||
installments_total: int | None = Field(default=None, ge=1)
|
||||
principal_amount: PositiveMoney | None = None
|
||||
contract_start: date | None = None
|
||||
contract_min_term_months: int | None = Field(default=None, ge=1)
|
||||
contract_notice_period_days: int | None = Field(default=None, ge=0)
|
||||
contract_auto_renew_months: int | None = Field(default=None, ge=1)
|
||||
contract_cancelled_at: date | None = None
|
||||
reserve_enabled: bool | None = None
|
||||
notes: str | None = None
|
||||
tags: list[str] | None = None
|
||||
is_active: bool | None = None
|
||||
|
||||
|
||||
class AmountVersionCreate(InputModel):
|
||||
amount: PositiveMoney
|
||||
valid_from: date = Field(description="Gilt für alle Fälligkeiten ab diesem Tag.")
|
||||
note: str | None = Field(default=None, examples=["Preiserhöhung laut Schreiben vom 01.06."])
|
||||
|
||||
|
||||
class AmountVersionOut(ApiModel):
|
||||
id: int
|
||||
recurrence_id: int
|
||||
amount: Money
|
||||
valid_from: date
|
||||
note: str | None
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class ContractTermOut(ApiModel):
|
||||
"""Laufende Vertragsperiode und Kündigungstermin."""
|
||||
|
||||
term_start: date
|
||||
term_end: date
|
||||
notice_deadline: date | None
|
||||
renews_on: date | None
|
||||
is_cancelled: bool
|
||||
|
||||
|
||||
class InstallmentStatusOut(ApiModel):
|
||||
"""Stand einer Ratenzahlung."""
|
||||
|
||||
total: int
|
||||
paid: int
|
||||
remaining: int
|
||||
paid_amount: Money
|
||||
remaining_amount: Money
|
||||
final_due_date: date | None
|
||||
|
||||
|
||||
class RecurrenceOut(ApiModel):
|
||||
id: int
|
||||
kind: EntryKind
|
||||
title: str
|
||||
merchant_id: int | None
|
||||
category_id: int
|
||||
account_id: int
|
||||
amount: Money
|
||||
is_variable: bool
|
||||
currency: str
|
||||
rrule: str
|
||||
dtstart: date
|
||||
until: date | None
|
||||
business_day_shift: BusinessDayShift
|
||||
holiday_region: str
|
||||
installments_total: int | None
|
||||
principal_amount: Money | None
|
||||
contract_start: date | None
|
||||
contract_min_term_months: int | None
|
||||
contract_notice_period_days: int | None
|
||||
contract_auto_renew_months: int | None
|
||||
contract_cancelled_at: date | None
|
||||
reserve_enabled: bool
|
||||
notes: str | None
|
||||
tags: list[str]
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class RecurrenceDetailOut(RecurrenceOut):
|
||||
"""Posten samt berechneter Zusatzangaben für die Detailansicht."""
|
||||
|
||||
merchant: MerchantOut | None = None
|
||||
amount_versions: list[AmountVersionOut] = Field(default_factory=list)
|
||||
next_dates: list[date] = Field(
|
||||
default_factory=list, description="Die nächsten fünf nominalen Termine."
|
||||
)
|
||||
monthly_reserve: Money | None = Field(
|
||||
default=None, description="Rücklage pro Monat, wenn `reserve_enabled` gesetzt ist."
|
||||
)
|
||||
annual_burden: Money = Field(description="Belastung der kommenden zwölf Monate.")
|
||||
contract_term: ContractTermOut | None = None
|
||||
installments: InstallmentStatusOut | None = None
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Schemata der Auswertungen."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.schemas.common import ApiModel, Money
|
||||
|
||||
|
||||
class TotalsOut(ApiModel):
|
||||
"""Einnahmen, Ausgaben und Saldo einer Sicht."""
|
||||
|
||||
income: Money
|
||||
expenses: Money
|
||||
balance: Money
|
||||
|
||||
|
||||
class MonthComparisonOut(ApiModel):
|
||||
"""Veränderung gegenüber dem Vormonat."""
|
||||
|
||||
income: Money
|
||||
expenses: Money
|
||||
balance: Money
|
||||
|
||||
|
||||
class MonthReportOut(ApiModel):
|
||||
"""Monatsübersicht mit Plan-Ist-Vergleich."""
|
||||
|
||||
month: date = Field(description="Immer der Monatserste.")
|
||||
planned: TotalsOut = Field(description="Soll aus Fälligkeiten und Buchungen.")
|
||||
actual: TotalsOut = Field(
|
||||
description="Ist aus bestätigten Fälligkeiten und allen einmaligen Buchungen."
|
||||
)
|
||||
previous_planned: TotalsOut
|
||||
previous_actual: TotalsOut
|
||||
delta_to_previous: MonthComparisonOut
|
||||
|
||||
fixed_costs: Money = Field(description="Ausgaben in Kategorien mit `is_fixed_cost`.")
|
||||
variable_costs: Money
|
||||
reserves: Money = Field(description="Summe der monatlichen Rücklagen.")
|
||||
available_after_fixed: Money = Field(description="Einkünfte abzüglich Fixkosten und Rücklagen.")
|
||||
|
||||
confirmed_count: int
|
||||
open_count: int
|
||||
skipped_count: int
|
||||
@@ -0,0 +1,48 @@
|
||||
"""Schemata für einmalige Buchungen."""
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.models.enums import EntryKind
|
||||
from app.schemas.common import ApiModel, InputModel, Money, PositiveMoney
|
||||
from app.schemas.merchant import MerchantOut
|
||||
|
||||
|
||||
class TransactionCreate(InputModel):
|
||||
kind: EntryKind
|
||||
title: str = Field(min_length=1, max_length=160, examples=["Wocheneinkauf"])
|
||||
merchant_id: int | None = None
|
||||
category_id: int
|
||||
account_id: int
|
||||
amount: PositiveMoney = Field(description="Immer positiv – die Richtung steckt in `kind`.")
|
||||
booking_date: date
|
||||
note: str | None = None
|
||||
tags: list[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
class TransactionUpdate(InputModel):
|
||||
kind: EntryKind | None = None
|
||||
title: str | None = Field(default=None, min_length=1, max_length=160)
|
||||
merchant_id: int | None = None
|
||||
category_id: int | None = None
|
||||
account_id: int | None = None
|
||||
amount: PositiveMoney | None = None
|
||||
booking_date: date | None = None
|
||||
note: str | None = None
|
||||
tags: list[str] | None = None
|
||||
|
||||
|
||||
class TransactionOut(ApiModel):
|
||||
id: int
|
||||
kind: EntryKind
|
||||
title: str
|
||||
merchant_id: int | None
|
||||
category_id: int
|
||||
account_id: int
|
||||
amount: Money
|
||||
booking_date: date
|
||||
note: str | None
|
||||
tags: list[str]
|
||||
created_at: datetime
|
||||
merchant: MerchantOut | None = None
|
||||
Reference in New Issue
Block a user