feat(b4w): add human-readable B4wExport repr/str output; fix comdirect account lookup and export formatting helpers
This commit is contained in:
@@ -34,10 +34,27 @@ def _parse_date_german(date_str: str) -> date | None:
|
||||
return date(day=day, month=month, year=year)
|
||||
|
||||
|
||||
def date2str(value: date | None, default="--", date_format="%Y-%m-%d") -> str:
|
||||
if value:
|
||||
return value.strftime(date_format)
|
||||
return default
|
||||
|
||||
|
||||
def _parse_decimal_german(decimal_str: str) -> Decimal:
|
||||
return Decimal(decimal_str.replace(".", "").replace(",", "."))
|
||||
|
||||
|
||||
def decimal2str(value: Decimal) -> str:
|
||||
value = Decimal(f"{value:.2f}")
|
||||
int_part, _, frac = str(value).partition(".")
|
||||
groups: list[str] = []
|
||||
while len(int_part) > 3:
|
||||
groups.insert(0, int_part[-3:])
|
||||
int_part = int_part[:-3]
|
||||
groups.insert(0, int_part or "0")
|
||||
return f"{'.'.join(groups)},{frac or '00'}"
|
||||
|
||||
|
||||
type Csv2DictRow = dict[str, str]
|
||||
type Csv2Dict = list[Csv2DictRow]
|
||||
type CsV2DictMulti = dict[str, Csv2Dict]
|
||||
|
||||
+31
-1
@@ -6,7 +6,14 @@ from sqlalchemy import Column, Date, ForeignKey, Integer, String, UniqueConstrai
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from src.constants import IBAN_PATTERN, Currency
|
||||
from src.models._common import BaseModelDb, ExportBaseModel, IngestdbBase, Sign, _hash
|
||||
from src.models._common import (
|
||||
BaseModelDb,
|
||||
ExportBaseModel,
|
||||
IngestdbBase,
|
||||
Sign,
|
||||
_hash,
|
||||
date2str,
|
||||
)
|
||||
|
||||
|
||||
class B4wExport(ExportBaseModel):
|
||||
@@ -32,6 +39,29 @@ class B4wExport(ExportBaseModel):
|
||||
)
|
||||
notes: str = Field(alias="Notes")
|
||||
|
||||
def parameters_to_str(self):
|
||||
return (
|
||||
f"Id1='{self.id}', "
|
||||
f"OwnrAcctIBAN='{self.account_iban!s}', "
|
||||
f"AmtCcy='{self.amount_currency!s}', "
|
||||
f"ValDt='{date2str(self.date_valid)}', "
|
||||
f"BookgDt='{date2str( self.date_book )}', "
|
||||
f"Amt='{self.amount!s}', "
|
||||
f"OwnrAcctCcy='{self.account_currency!s}', "
|
||||
f"CdtDbtInd='{self.sign!s}', "
|
||||
f"RmtInf='{self.reference}', "
|
||||
f"RmtdNm='{self.other_name}', "
|
||||
f"RmtdAcctIBAN='{self.other_iban}', "
|
||||
f"Category='{self.category.to_str() if self.category else ''}', "
|
||||
f"Notes='{self.notes}'"
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"B4wExport({self.parameters_to_str()})"
|
||||
|
||||
def __str__(self):
|
||||
return f"B4wExport({self.parameters_to_str()})"
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def hash_id(self) -> str:
|
||||
|
||||
Reference in New Issue
Block a user