Files
data-entry-app/backend/app/schemas/raw_material.py
T
2026-05-10 09:46:07 +12:00

56 lines
1.7 KiB
Python

from datetime import date, datetime
from pydantic import BaseModel, ConfigDict, Field
class RawMaterialPriceVersionCreate(BaseModel):
model_config = ConfigDict(extra="forbid")
market_value: float = Field(gt=0)
waste_percentage: float = Field(ge=0, default=0.0)
effective_date: date
status: str = "active"
notes: str | None = Field(default=None, max_length=2000)
class RawMaterialPriceVersionRead(RawMaterialPriceVersionCreate):
id: int
created_at: datetime
loss_cost: float
cost_per_unit: float
cost_per_kg: float
model_config = ConfigDict(from_attributes=True)
class RawMaterialCreate(BaseModel):
model_config = ConfigDict(extra="forbid")
name: str = Field(min_length=1, max_length=255)
supplier: str | None = Field(default=None, max_length=255)
unit_of_measure: str = Field(min_length=1, max_length=64)
kg_per_unit: float = Field(gt=0)
status: str = "active"
notes: str | None = Field(default=None, max_length=2000)
initial_price: RawMaterialPriceVersionCreate
class RawMaterialUpdate(BaseModel):
model_config = ConfigDict(extra="forbid")
supplier: str | None = Field(default=None, max_length=255)
unit_of_measure: str | None = Field(default=None, min_length=1, max_length=64)
kg_per_unit: float | None = Field(default=None, gt=0)
status: str | None = None
notes: str | None = Field(default=None, max_length=2000)
class RawMaterialRead(BaseModel):
id: int
tenant_id: str
name: str
supplier: str | None
unit_of_measure: str
kg_per_unit: float
status: str
notes: str | None
created_at: datetime
current_price: RawMaterialPriceVersionRead | None
model_config = ConfigDict(from_attributes=True)