Files
celtic-life-science/app/stockists/schemas.py
Shubhankar45 0d30c58bf0 Server backup 2026-11-07 of uncommitted work in projects/pharma-web-celtic
Snapshot of the working tree on srv1071960 (branch main), taken during
server cleanup. .env files, node_modules, builds, logs and media were excluded.
2026-11-07 05:43:12 +00:00

59 lines
1.9 KiB
Python

import uuid
from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, computed_field, model_validator
class StockistCreate(BaseModel):
headquarters_id: uuid.UUID
name: str = Field(min_length=2, max_length=200)
address: str | None = Field(default=None, min_length=2, max_length=500)
shop_address: str | None = Field(default=None, min_length=2, max_length=500)
contact_number: str | None = Field(default=None, max_length=20)
@model_validator(mode="after")
def resolve_address(self) -> "StockistCreate":
if not self.address and not self.shop_address:
raise ValueError("Address is required")
if not self.address:
self.address = self.shop_address
return self
class StockistUpdate(BaseModel):
headquarters_id: uuid.UUID | None = None
name: str | None = Field(default=None, min_length=2, max_length=200)
address: str | None = Field(default=None, min_length=2, max_length=500)
shop_address: str | None = Field(default=None, min_length=2, max_length=500)
contact_number: str | None = Field(default=None, max_length=20)
is_active: bool | None = None
@model_validator(mode="after")
def resolve_address(self) -> "StockistUpdate":
if self.address is None and self.shop_address is not None:
self.address = self.shop_address
return self
class StockistRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
headquarters_id: uuid.UUID
name: str
address: str
contact_number: str | None
is_active: bool
approval_status: str
rejection_reason: str | None
requested_by_name: str | None
created_at: datetime
#: Filled by the list endpoint only: the MRs working this stockist's headquarters.
assigned_mr_name: str | None = None
@computed_field
@property
def shop_address(self) -> str:
return self.address