Files
data-entry-app/backend/app/schemas/raw_material.py
T

56 lines
1.7 KiB
Python
Raw Normal View History

2026-04-25 20:43:37 +12:00
from datetime import date, datetime
from pydantic import BaseModel, ConfigDict, Field
class RawMaterialPriceVersionCreate(BaseModel):
2026-05-10 09:46:07 +12:00
model_config = ConfigDict(extra="forbid")
2026-04-25 20:43:37 +12:00
market_value: float = Field(gt=0)
waste_percentage: float = Field(ge=0, default=0.0)
effective_date: date
status: str = "active"
2026-05-10 09:46:07 +12:00
notes: str | None = Field(default=None, max_length=2000)
2026-04-25 20:43:37 +12:00
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):
2026-05-10 09:46:07 +12:00
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)
2026-04-25 20:43:37 +12:00
kg_per_unit: float = Field(gt=0)
status: str = "active"
2026-05-10 09:46:07 +12:00
notes: str | None = Field(default=None, max_length=2000)
2026-04-25 20:43:37 +12:00
initial_price: RawMaterialPriceVersionCreate
class RawMaterialUpdate(BaseModel):
2026-05-10 09:46:07 +12:00
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)
2026-04-25 20:43:37 +12:00
kg_per_unit: float | None = Field(default=None, gt=0)
status: str | None = None
2026-05-10 09:46:07 +12:00
notes: str | None = Field(default=None, max_length=2000)
2026-04-25 20:43:37 +12:00
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)