## Summary - Calibrate label print/calibrate CSS to the reference PDF (positions, ~7pt/6pt sizes, bottom-row pitch) - Print layout: partial last-box weight, pad short pages to 4 slips, whole-number weights - Rename to Lithium Label Manager; Vazirmatn for FA / Inter for EN; inverted lithium icon; seed weights=5; number step=1; hide empty toast ## Test plan - [ ] Print calibration sheet and overlay on a physical label — top and bottom rows align - [ ] Order 50/5/4 — box labels show 20, 20, 10 (padded page); weights without `.0` - [ ] Language toggle switches Inter ↔ Vazirmatn - [ ] Seed products use canister weight 5; form spinners step by 1 Reviewed-on: #3 Co-authored-by: Diaco Soltanpour <dyaco8464@yahoo.com> Co-committed-by: Diaco Soltanpour <dyaco8464@yahoo.com>
66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
from typing import List, Optional
|
|
from django.shortcuts import get_object_or_404
|
|
from django.utils import timezone
|
|
from ninja import NinjaAPI, Query
|
|
|
|
from .models import Product, Order
|
|
from .schemas import ProductOut, ProductIn, OrderOut, OrderIn, OrderStatusIn
|
|
|
|
api = NinjaAPI(title='Lithium Label API', version='1.0.0', urls_namespace='slips_api')
|
|
|
|
|
|
# ─── Products ────────────────────────────────────────────
|
|
|
|
@api.get('/products', response=List[ProductOut], tags=['Products'])
|
|
def list_products(request):
|
|
return Product.objects.all()
|
|
|
|
|
|
@api.post('/products', response={201: ProductOut}, tags=['Products'])
|
|
def create_product(request, payload: ProductIn):
|
|
product = Product.objects.create(**payload.dict())
|
|
return 201, product
|
|
|
|
|
|
# ─── Orders ──────────────────────────────────────────────
|
|
|
|
@api.get('/orders', response=List[OrderOut], tags=['Orders'])
|
|
def list_orders(request, status: Optional[str] = Query(None)):
|
|
qs = Order.objects.select_related('product').all()
|
|
if status:
|
|
qs = qs.filter(status=status)
|
|
return qs
|
|
|
|
|
|
@api.post('/orders', response={201: OrderOut}, tags=['Orders'])
|
|
def create_order(request, payload: OrderIn):
|
|
product = get_object_or_404(Product, id=payload.product_id)
|
|
order = Order(
|
|
product=product,
|
|
batch_number=payload.batch_number,
|
|
production_date=payload.production_date,
|
|
next_control_date=payload.next_control_date,
|
|
total_weight=payload.total_weight,
|
|
canister_weight=payload.canister_weight,
|
|
canisters_per_box=payload.canisters_per_box,
|
|
)
|
|
order.save()
|
|
return 201, order
|
|
|
|
|
|
@api.patch('/orders/{order_id}', response=OrderOut, tags=['Orders'])
|
|
def update_order_status(request, order_id: int, payload: OrderStatusIn):
|
|
order = get_object_or_404(Order, id=order_id)
|
|
order.status = payload.status
|
|
if payload.status == 'done':
|
|
order.printed_at = timezone.now()
|
|
order.save()
|
|
return order
|
|
|
|
|
|
@api.delete('/orders/{order_id}', response={204: None}, tags=['Orders'])
|
|
def delete_order(request, order_id: int):
|
|
order = get_object_or_404(Order, id=order_id)
|
|
order.delete()
|
|
return 204, None
|