heavy refactor
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
from pydantic import BaseModel, Field, computed_field, field_validator
|
||||
from sqlalchemy import Column, Date, String
|
||||
|
||||
from src.models._common import (
|
||||
IngestdbBase,
|
||||
_hash,
|
||||
_parse_date_german,
|
||||
_parse_decimal_german,
|
||||
)
|
||||
|
||||
|
||||
class ComdirectBase(BaseModel):
|
||||
date_val: date | None = Field(
|
||||
alias="Wertstellung (Valuta)", examples=["07.09.2026"]
|
||||
)
|
||||
amount_eur: Decimal = Field(alias="Umsatz in EUR", examples=["32,43"])
|
||||
|
||||
@field_validator("date_val", mode="before")
|
||||
@classmethod
|
||||
def parse_date_val(cls, date_str: str) -> date | None:
|
||||
return _parse_date_german(date_str)
|
||||
|
||||
@field_validator("amount_eur", mode="before")
|
||||
@classmethod
|
||||
def parse_amount(cls, decimal_str: str) -> Decimal:
|
||||
return _parse_decimal_german(decimal_str)
|
||||
|
||||
|
||||
class ComdirectGiro(ComdirectBase):
|
||||
date_book: date | None = Field(alias="Buchungstag", examples=["07.09.2026"])
|
||||
type: str = Field(
|
||||
alias="Vorgang", examples=["Lastschrift / Belastung", "Kartenumsatz"]
|
||||
)
|
||||
text: str = Field(alias="Buchungstext")
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def hash_id(self) -> str:
|
||||
return _hash(self.date_val, self.date_book, self.text)
|
||||
|
||||
@field_validator("date_book", mode="before")
|
||||
@classmethod
|
||||
def parse_date_book(cls, date_str: str) -> date | None:
|
||||
return _parse_date_german(date_str)
|
||||
|
||||
|
||||
class ComdirectCreditCard(ComdirectGiro):
|
||||
# "Buchungstag";"Umsatztag";"Vorgang";"Referenz";"Buchungstext";"Umsatz in EUR";
|
||||
date_book: date | None = Field(alias="Buchungstag", examples=["07.09.2026"])
|
||||
date_val: date | None = Field(alias="Umsatztag", default=None)
|
||||
type: str = Field(
|
||||
alias="Vorgang",
|
||||
examples=["Lastschrift / Belastung", "Kartenumsatz"],
|
||||
default="",
|
||||
)
|
||||
reference: str = Field(alias="Referenz", default="")
|
||||
text: str = Field(alias="Buchungstext", default="")
|
||||
amount_eur: Decimal | None = Field(
|
||||
alias="Umsatz in EUR", examples=["32,43"], default=None
|
||||
)
|
||||
|
||||
|
||||
class ComdirectDepot(ComdirectBase):
|
||||
date_val: date | None = Field(alias="Geschäftstag")
|
||||
num: Decimal = Field(alias="Stück / Nom.")
|
||||
name: str = Field(alias="Bezeichnung")
|
||||
wkn: str = Field(alias="WKN")
|
||||
currency: str = Field(alias="Währung")
|
||||
spot_price: Decimal = Field(alias="Ausführungskurs")
|
||||
|
||||
@field_validator("num", "spot_price", mode="before")
|
||||
@classmethod
|
||||
def parse_decimals(cls, decimal_in: str) -> Decimal:
|
||||
return _parse_decimal_german(decimal_in)
|
||||
|
||||
|
||||
class ComdirectBaseDb(IngestdbBase):
|
||||
__abstract__ = True
|
||||
|
||||
|
||||
class ComdirectGiroDb(ComdirectBaseDb):
|
||||
__tablename__ = "comdirect_giro"
|
||||
|
||||
type = Column(String, nullable=True)
|
||||
date_book = Column(Date, nullable=True)
|
||||
Reference in New Issue
Block a user