136 lines
4.0 KiB
Python
136 lines
4.0 KiB
Python
# ================================================================
|
|
# services/data/app/schemas/sales.py - MISSING FILE
|
|
# ================================================================
|
|
"""Sales data schemas"""
|
|
|
|
from pydantic import BaseModel, Field, validator
|
|
from datetime import datetime
|
|
from typing import Optional, List, Dict, Any
|
|
from uuid import UUID
|
|
|
|
class SalesDataCreate(BaseModel):
|
|
"""Schema for creating sales data"""
|
|
tenant_id: UUID
|
|
date: datetime
|
|
product_name: str = Field(..., min_length=1, max_length=255)
|
|
quantity_sold: int = Field(..., gt=0)
|
|
revenue: float = Field(..., gt=0)
|
|
location_id: Optional[str] = Field(None, max_length=100)
|
|
source: str = Field(default="manual", max_length=50)
|
|
notes: Optional[str] = Field(None, max_length=500)
|
|
|
|
@validator('product_name')
|
|
def normalize_product_name(cls, v):
|
|
return v.strip().lower()
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesDataResponse(BaseModel):
|
|
"""Schema for sales data response"""
|
|
id: UUID
|
|
tenant_id: UUID
|
|
date: datetime
|
|
product_name: str
|
|
quantity_sold: int
|
|
revenue: float
|
|
location_id: Optional[str]
|
|
source: str
|
|
notes: Optional[str]
|
|
created_at: datetime
|
|
updated_at: Optional[datetime]
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesDataQuery(BaseModel):
|
|
"""Schema for querying sales data"""
|
|
tenant_id: UUID
|
|
start_date: Optional[datetime] = None
|
|
end_date: Optional[datetime] = None
|
|
product_names: Optional[List[str]] = None
|
|
location_ids: Optional[List[str]] = None
|
|
sources: Optional[List[str]] = None
|
|
min_quantity: Optional[int] = None
|
|
max_quantity: Optional[int] = None
|
|
min_revenue: Optional[float] = None
|
|
max_revenue: Optional[float] = None
|
|
limit: Optional[int] = Field(default=1000, le=5000)
|
|
offset: Optional[int] = Field(default=0, ge=0)
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesDataImport(BaseModel):
|
|
"""Schema for importing sales data"""
|
|
tenant_id: UUID
|
|
data: str # JSON string or CSV content
|
|
data_format: str = Field(..., pattern="^(csv|json|excel)$")
|
|
source: str = Field(default="import", max_length=50)
|
|
validate_only: bool = Field(default=False)
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesDataBulkCreate(BaseModel):
|
|
"""Schema for bulk creating sales data"""
|
|
tenant_id: UUID
|
|
records: List[Dict[str, Any]]
|
|
source: str = Field(default="bulk_import", max_length=50)
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesValidationResult(BaseModel):
|
|
"""Schema for sales data validation result"""
|
|
is_valid: bool
|
|
total_records: int
|
|
valid_records: int
|
|
invalid_records: int
|
|
errors: List[Dict[str, Any]]
|
|
warnings: List[Dict[str, Any]]
|
|
summary: Dict[str, Any]
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesImportResult(BaseModel):
|
|
"""Schema for sales import result"""
|
|
success: bool
|
|
records_processed: int
|
|
records_created: int
|
|
records_updated: int
|
|
records_failed: int
|
|
errors: List[Dict[str, Any]]
|
|
warnings: List[Dict[str, Any]]
|
|
processing_time_seconds: float
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesAggregation(BaseModel):
|
|
"""Schema for sales aggregation results"""
|
|
period: str # "daily", "weekly", "monthly"
|
|
date: datetime
|
|
product_name: Optional[str] = None
|
|
total_quantity: int
|
|
total_revenue: float
|
|
average_quantity: float
|
|
average_revenue: float
|
|
record_count: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class SalesExportRequest(BaseModel):
|
|
"""Schema for sales export request"""
|
|
tenant_id: UUID
|
|
format: str = Field(..., pattern="^(csv|json|excel)$")
|
|
start_date: Optional[datetime] = None
|
|
end_date: Optional[datetime] = None
|
|
product_names: Optional[List[str]] = None
|
|
location_ids: Optional[List[str]] = None
|
|
include_metadata: bool = Field(default=True)
|
|
|
|
class Config:
|
|
from_attributes = True |