Improve CarPass product UX and service flows
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, model_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||
|
||||
from app.models.expense import ServiceType
|
||||
from app.models.expense import ExpenseCategory, ServiceType
|
||||
|
||||
|
||||
class FuelEntryBase(BaseModel):
|
||||
@@ -87,6 +87,62 @@ class ServiceEntryRead(ServiceEntryBase):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class ExpenseEntryBase(BaseModel):
|
||||
entry_date: date
|
||||
category: ExpenseCategory
|
||||
title: str
|
||||
vendor: str | None = None
|
||||
total_cost: Decimal
|
||||
currency: str = "RUB"
|
||||
odometer: int | None = None
|
||||
period_start: date | None = None
|
||||
period_end: date | None = None
|
||||
period_months: int | None = None
|
||||
is_recurring: bool = False
|
||||
notes: str | None = None
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_period(self) -> "ExpenseEntryBase":
|
||||
if self.period_months is not None and self.period_months < 1:
|
||||
raise ValueError("period_months must be positive")
|
||||
if self.period_start and self.period_end and self.period_end < self.period_start:
|
||||
raise ValueError("period_end must be after period_start")
|
||||
return self
|
||||
|
||||
|
||||
class ExpenseEntryCreate(ExpenseEntryBase):
|
||||
car_id: int
|
||||
|
||||
|
||||
class ExpenseEntryUpdate(BaseModel):
|
||||
entry_date: date | None = None
|
||||
category: ExpenseCategory | None = None
|
||||
title: str | None = None
|
||||
vendor: str | None = None
|
||||
total_cost: Decimal | None = None
|
||||
currency: str | None = None
|
||||
odometer: int | None = None
|
||||
period_start: date | None = None
|
||||
period_end: date | None = None
|
||||
period_months: int | None = None
|
||||
is_recurring: bool | None = None
|
||||
notes: str | None = None
|
||||
|
||||
|
||||
class ExpenseEntryRead(ExpenseEntryBase):
|
||||
id: int
|
||||
car_id: int
|
||||
created_at: datetime
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class OwnershipCategoryBreakdown(BaseModel):
|
||||
category: str
|
||||
total_cost: Decimal
|
||||
entries_count: int
|
||||
|
||||
|
||||
class OwnershipStats(BaseModel):
|
||||
car_id: int
|
||||
date_from: date
|
||||
@@ -94,6 +150,14 @@ class OwnershipStats(BaseModel):
|
||||
fuel_cost: Decimal
|
||||
service_cost: Decimal
|
||||
total_cost: Decimal
|
||||
expenses_cost: Decimal = Decimal("0")
|
||||
recurring_costs: Decimal = Decimal("0")
|
||||
one_time_costs: Decimal = Decimal("0")
|
||||
forecast_next_month: Decimal = Decimal("0")
|
||||
depreciation_cost: Decimal = Decimal("0")
|
||||
cost_per_month: Decimal = Decimal("0")
|
||||
cost_by_category: dict[str, Decimal] = Field(default_factory=dict)
|
||||
categories: list[OwnershipCategoryBreakdown] = Field(default_factory=list)
|
||||
liters: Decimal
|
||||
distance_km: int
|
||||
avg_consumption_l_per_100km: float | None
|
||||
|
||||
Reference in New Issue
Block a user