Add order count edit, remove, and undo-done
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
27
slips/api.py
27
slips/api.py
@@ -5,7 +5,7 @@ from ninja import NinjaAPI, Query
|
||||
|
||||
from .models import Product, Order
|
||||
from .schemas import (
|
||||
ProductOut, ProductIn, OrderOut, OrderIn, OrderStatusIn,
|
||||
ProductOut, ProductIn, OrderOut, OrderIn, OrderUpdateIn,
|
||||
CalibrationIn, CalibrationOut,
|
||||
)
|
||||
from .calibration import load_calibration, save_calibration, DEFAULTS, for_api
|
||||
@@ -48,16 +48,31 @@ def create_order(request, payload: OrderIn):
|
||||
canister_weight=payload.canister_weight,
|
||||
canisters_per_box=payload.canisters_per_box,
|
||||
)
|
||||
order.apply_weight()
|
||||
order.save()
|
||||
return 201, order
|
||||
|
||||
|
||||
@api.patch('/orders/{order_id}', response=OrderOut, tags=['Orders'])
|
||||
def update_order_status(request, order_id: int, payload: OrderStatusIn):
|
||||
@api.patch('/orders/{order_id}', response={200: OrderOut, 400: dict}, tags=['Orders'])
|
||||
def update_order(request, order_id: int, payload: OrderUpdateIn):
|
||||
order = get_object_or_404(Order, id=order_id)
|
||||
order.status = payload.status
|
||||
if payload.status == 'done':
|
||||
order.printed_at = timezone.now()
|
||||
|
||||
if payload.canister_count is not None or payload.box_count is not None:
|
||||
if order.status != 'pending':
|
||||
return 400, {'detail': 'Only pending orders can change label counts'}
|
||||
if payload.canister_count is not None and payload.canister_count < 1:
|
||||
return 400, {'detail': 'canister_count must be >= 1'}
|
||||
if payload.box_count is not None and payload.box_count < 1:
|
||||
return 400, {'detail': 'box_count must be >= 1'}
|
||||
order.set_counts(payload.canister_count, payload.box_count)
|
||||
|
||||
if payload.status is not None:
|
||||
order.status = payload.status
|
||||
if payload.status == 'done':
|
||||
order.printed_at = timezone.now()
|
||||
elif payload.status == 'pending':
|
||||
order.printed_at = None
|
||||
|
||||
order.save()
|
||||
return order
|
||||
|
||||
|
||||
Reference in New Issue
Block a user