48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from beanie import Document
|
|
from bson import Decimal128
|
|
from pydantic import BaseModel, validator
|
|
from decimal import Decimal
|
|
|
|
from backend.services.project.constants import MilestoneStatus
|
|
|
|
|
|
class Milestone(BaseModel):
|
|
index: int
|
|
status: MilestoneStatus
|
|
description: str
|
|
update_time: datetime
|
|
expected_payment: Decimal
|
|
actual_paid: Decimal
|
|
|
|
@validator("expected_payment", pre=True)
|
|
def convert_decimal128_expected_payment(cls, value):
|
|
if isinstance(value, Decimal128):
|
|
return value.to_decimal() # Convert MongoDB Decimal128 to Python Decimal
|
|
return value
|
|
|
|
@validator("actual_paid", pre=True)
|
|
def convert_decimal128_actual_paid(cls, value):
|
|
if isinstance(value, Decimal128):
|
|
return value.to_decimal() # Convert MongoDB Decimal128 to Python Decimal
|
|
return value
|
|
|
|
|
|
class ProjectDoc(Document):
|
|
product_id: str
|
|
request_id: str
|
|
requester_id: str
|
|
proposal_id: str
|
|
proposer_id: str
|
|
current_milestone: int
|
|
milestones: List[Milestone] = []
|
|
code_depot_id: Optional[str]
|
|
payment_currency: str
|
|
providers: List[str] = []
|
|
issuers: List[str] = []
|
|
|
|
class Settings:
|
|
name = "project_store"
|