Files
product-slip/slips/schemas.py
2026-11-11 14:53:44 +03:30

126 lines
2.6 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
class CrmOrderOut(Schema):
sales_office: str
customer_name: str
delivery_note_date: str
product_code: str
product_title: str
note_quantity: str
delivered_quantity: str
remaining_quantity: str
warehouse_delivery_date: str
delivery_note_number: str
notes: str
class CrmLoginIn(Schema):
username: str
password: str
class CrmOrdersOut(Schema):
since: str
username: str
orders: List[CrmOrderOut]