factories init (tbc)
This commit is contained in:
+16
-14
@@ -22,6 +22,20 @@ class Currency(str, Enum):
|
||||
return f"Currency.{self.name}"
|
||||
|
||||
|
||||
class Sign(str, Enum):
|
||||
DEBIT = "DBIT"
|
||||
CREDIT = "CRDT"
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
def __repr__(self):
|
||||
return f"Sign.{self.name}"
|
||||
|
||||
def to_sign(self) -> int:
|
||||
return -1 if self is Sign.DEBIT else 1
|
||||
|
||||
|
||||
class B4wExport(BaseModel):
|
||||
id: int = Field(alias="Id1", description="internal B4w ID")
|
||||
account_iban: str = Field(alias="OwnrAcctIBAN", pattern=IBAN_PATTERN)
|
||||
@@ -30,7 +44,7 @@ class B4wExport(BaseModel):
|
||||
date_book: date = Field(alias="BookgDt")
|
||||
amount: Decimal = Field(alias="Amt")
|
||||
amount_currency: Currency = Field(alias="AmtCcy")
|
||||
sign: int = Field(alias="CdtDbtInd")
|
||||
sign: Sign = Field(alias="CdtDbtInd")
|
||||
reference: str = Field(alias="RmtInf")
|
||||
other_name: str = Field(alias="RmtdNm")
|
||||
other_iban: str = Field(alias="RmtdAcctIBAN")
|
||||
@@ -39,19 +53,7 @@ class B4wExport(BaseModel):
|
||||
|
||||
@property
|
||||
def amount_signed(self) -> Decimal:
|
||||
return self.amount * self.sign
|
||||
|
||||
@field_validator("sign", mode="before")
|
||||
@classmethod
|
||||
def get_sign(cls, input_value: str) -> int:
|
||||
if input_value == "DBIT":
|
||||
return -1
|
||||
elif input_value == "CRDT":
|
||||
return 1
|
||||
else:
|
||||
raise ValidationError(
|
||||
f"Invalid amount type: {input_value}. Expected DBIT or CRDT"
|
||||
)
|
||||
return self.amount * self.sign.to_sign()
|
||||
|
||||
@field_validator("category", mode="before")
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user