from datetime import date from typing import Optional from ninja import Schema class ProductOut(Schema): id: int code: str description: str default_net_weight: float requires_dates: bool class ProductIn(Schema): code: str description: str default_net_weight: float = 5.0 requires_dates: bool = True class OrderIn(Schema): product_id: int batch_number: str production_date: Optional[date] = None next_control_date: Optional[date] = None total_weight: float canister_weight: float canisters_per_box: int class OrderOut(Schema): id: int product_id: int product_code: str product_description: str batch_number: str production_date: Optional[date] = None next_control_date: Optional[date] = None total_weight: float canister_weight: float canisters_per_box: int canister_count: int box_count: int canister_pages: int box_pages: int status: str created_at: str printed_at: Optional[str] = None @staticmethod def resolve_product_code(obj): return obj.product.code @staticmethod def resolve_product_description(obj): return obj.product.description @staticmethod def resolve_created_at(obj): return obj.created_at.strftime('%d/%m/%Y %H:%M') @staticmethod def resolve_printed_at(obj): if obj.printed_at: return obj.printed_at.strftime('%d/%m/%Y %H:%M') return None class OrderUpdateIn(Schema): status: Optional[str] = None canister_count: Optional[int] = None box_count: Optional[int] = None class FieldCalibration(Schema): top: float left: float font: float bottom_top: float bottom_left: Optional[float] = None right_left: Optional[float] = None class CalibrationIn(Schema): batch: FieldCalibration date: FieldCalibration next: FieldCalibration weight: FieldCalibration class CalibrationOut(CalibrationIn): pass