74 lines
1.7 KiB
Python
74 lines
1.7 KiB
Python
|
|
"""Pydantic schemas for Deal endpoints."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from datetime import date, datetime
|
||
|
|
from decimal import Decimal
|
||
|
|
from typing import Optional
|
||
|
|
|
||
|
|
from pydantic import BaseModel, ConfigDict, Field
|
||
|
|
|
||
|
|
from app.models.deal import DealStage
|
||
|
|
|
||
|
|
|
||
|
|
class DealBase(BaseModel):
|
||
|
|
title: str = Field(..., min_length=1, max_length=255)
|
||
|
|
value: Decimal = Field(default=Decimal("0"), max_digits=12, decimal_places=2)
|
||
|
|
currency: str = Field(default="EUR", min_length=3, max_length=3)
|
||
|
|
stage: DealStage = DealStage.lead
|
||
|
|
close_date: Optional[date] = None
|
||
|
|
account_id: int
|
||
|
|
won_lost_reason: Optional[str] = Field(None, max_length=512)
|
||
|
|
|
||
|
|
|
||
|
|
class DealCreate(DealBase):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class DealUpdate(BaseModel):
|
||
|
|
title: Optional[str] = Field(None, min_length=1, max_length=255)
|
||
|
|
value: Optional[Decimal] = Field(None, max_digits=12, decimal_places=2)
|
||
|
|
currency: Optional[str] = Field(None, min_length=3, max_length=3)
|
||
|
|
close_date: Optional[date] = None
|
||
|
|
won_lost_reason: Optional[str] = Field(None, max_length=512)
|
||
|
|
|
||
|
|
|
||
|
|
class DealOut(DealBase):
|
||
|
|
model_config = ConfigDict(from_attributes=True)
|
||
|
|
|
||
|
|
id: int
|
||
|
|
org_id: int
|
||
|
|
owner_id: int
|
||
|
|
created_at: datetime
|
||
|
|
updated_at: datetime
|
||
|
|
deleted_at: Optional[datetime] = None
|
||
|
|
|
||
|
|
|
||
|
|
class DealListItem(DealOut):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class DealStageUpdate(BaseModel):
|
||
|
|
"""Body for PATCH /api/v1/deals/{id}/stage."""
|
||
|
|
|
||
|
|
stage: DealStage
|
||
|
|
reason: Optional[str] = Field(None, max_length=512)
|
||
|
|
|
||
|
|
|
||
|
|
class DealPipelineOut(BaseModel):
|
||
|
|
"""A single stage's slice of the pipeline."""
|
||
|
|
|
||
|
|
stage: DealStage
|
||
|
|
count: int
|
||
|
|
total_value: float
|
||
|
|
|
||
|
|
|
||
|
|
__all__ = [
|
||
|
|
"DealCreate",
|
||
|
|
"DealListItem",
|
||
|
|
"DealOut",
|
||
|
|
"DealPipelineOut",
|
||
|
|
"DealStageUpdate",
|
||
|
|
"DealUpdate",
|
||
|
|
]
|