34 lines
951 B
Python
34 lines
951 B
Python
from dataclasses import dataclass, field
|
|
from uuid import UUID, uuid4
|
|
|
|
|
|
@dataclass
|
|
class RecurringCashflow:
|
|
id: UUID = field(default_factory=uuid4)
|
|
start_date: str = ""
|
|
end_date: str = ""
|
|
frequency: str = "monthly"
|
|
amount: float = 0.0
|
|
category: str = ""
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": str(self.id),
|
|
"start_date": self.start_date,
|
|
"end_date": self.end_date,
|
|
"frequency": self.frequency,
|
|
"amount": self.amount,
|
|
"category": self.category,
|
|
}
|
|
|
|
@classmethod
|
|
def from_dict(cls, data: dict) -> "RecurringCashflow":
|
|
return cls(
|
|
id=UUID(data["id"]),
|
|
start_date=data.get("start_date", ""),
|
|
end_date=data.get("end_date", ""),
|
|
frequency=data.get("frequency", "monthly"),
|
|
amount=data.get("amount", 0.0),
|
|
category=data.get("category", ""),
|
|
)
|