- Implemented the items tab form in Svelte for editing invoices, displaying item quantities and import values. - Created saveInvoice function to handle both creation and updating of invoices, including validation of required fields and building a unified payload for API requests. - Added support for compliance, financials, and logistics data in the invoice payload.
88 lines
3.1 KiB
Python
88 lines
3.1 KiB
Python
"""
|
|
Schemas for Items and related entities
|
|
Complete nested one-to-one structure:
|
|
Item -> LineItem -> LineFinancial -> LineQuantity -> LineCustoms -> LineDescription -> LineReference
|
|
"""
|
|
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
# Import schemas from individual modules
|
|
from .line_items.schemas import (
|
|
LineItemCreate,
|
|
LineItemUpdate,
|
|
LineItemResponse
|
|
)
|
|
|
|
|
|
# ============================================================================
|
|
# ITEM SCHEMAS
|
|
# ============================================================================
|
|
|
|
class ItemBase(BaseModel):
|
|
"""Base schema for items"""
|
|
invoice_id: int = Field(..., description="Invoice ID")
|
|
item_type: str = Field(..., max_length=20,
|
|
description="Item type: IMPORT_TEMP, IMPORT_DEF, EXPORT, REPAIR")
|
|
system_origin: str = Field(..., max_length=10,
|
|
description="System origin: SCAF or SCAII")
|
|
|
|
# Item references
|
|
invoice_number: Optional[str] = Field(
|
|
None, max_length=15, description="Invoice number")
|
|
reference_number: Optional[str] = Field(
|
|
None, max_length=20, description="Reference number")
|
|
order: Optional[str] = Field(None, max_length=50, description="Order")
|
|
guide_number: Optional[str] = Field(
|
|
None, max_length=50, description="Guide number")
|
|
|
|
# Dates
|
|
invoice_date: Optional[int] = Field(None, description="Invoice date")
|
|
depreciation_date: Optional[int] = Field(
|
|
None, description="Depreciation date")
|
|
|
|
# Administrative fields
|
|
rectification: Optional[int] = Field(None, description="Rectification")
|
|
warehouse: Optional[str] = Field(
|
|
None, max_length=30, description="Warehouse")
|
|
location: Optional[str] = Field(
|
|
None, max_length=200, description="Location")
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
"""Schema for creating item with nested lines (one-to-many)"""
|
|
lines: Optional[list[LineItemCreate]] = Field(
|
|
default=[], description="List of line items")
|
|
|
|
|
|
class ItemUpdate(ItemBase):
|
|
"""Schema for updating item"""
|
|
invoice_id: Optional[int] = Field(None, description="Invoice ID")
|
|
item_type: Optional[str] = Field(
|
|
None, max_length=20, description="Item type")
|
|
system_origin: Optional[str] = Field(
|
|
None, max_length=10, description="System origin")
|
|
lines: Optional[list[LineItemUpdate]] = Field(
|
|
None, description="List of line items to update")
|
|
|
|
|
|
class ItemResponse(ItemBase):
|
|
"""Schema for item response with nested data (one-to-many)"""
|
|
id: int
|
|
lines: list[LineItemResponse] = Field(
|
|
default=[], description="List of line items")
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class ItemListResponse(BaseModel):
|
|
"""Schema for paginated item list"""
|
|
total: int = Field(..., description="Total number of items")
|
|
items: list[ItemResponse] = Field(..., description="List of items")
|
|
skip: int = Field(..., description="Number of skipped items")
|
|
limit: int = Field(..., description="Maximum items per page")
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|