101 lines
2.2 KiB
Python
101 lines
2.2 KiB
Python
from datetime import date
|
|
from typing import List, 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 CustomLabel(Schema):
|
|
weight: float
|
|
count: int
|
|
|
|
|
|
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
|
|
custom_labels: Optional[List[CustomLabel]] = None
|
|
|
|
|
|
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
|
|
custom_labels: List[CustomLabel]
|
|
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
|
|
custom_labels: Optional[List[CustomLabel]] = 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
|