-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_data_parsing.py
42 lines (37 loc) · 1.19 KB
/
input_data_parsing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pydantic import BaseModel, Field, ValidationError, model_validator
from datetime import datetime
class IDAddress(BaseModel):
address: str
city: str
country_code: str
class IDTransaction(BaseModel):
first_name: str
last_name: str
social_number: str | None = Field(default=None)
birthdate: datetime
address: list[IDAddress]
tph_number: list[str]
email: list[str]
transaction_date: datetime
local_amount: int
foreign_amount: int
reference_ag: str | None = Field(default=None)
reference_bg: str | None = Field(default=None)
iban_from: str | None = Field(default=None)
iban_to: str | None = Field(default=None)
@model_validator(mode="before")
def convert_amount_str_to_int(cls, values):
# convert str amount to int
amount = values.get("amount")
if isinstance(amount, str):
values["amount"] = int(amount.replace(" ", "").replace("kr", ""))
return values
class IDClass(BaseModel):
customer_id: str
market: str
report_date: datetime
# OP = Over Payment, OB = On Behalf
type: str = Field(pattern="^(OP|OB)$")
reason: str
action: str
transactions: list[IDTransaction]