Add per-product flag to skip Date and Next Control

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-14 12:06:12 +03:30
parent 6bbb8568c6
commit f9c6f3bc14
14 changed files with 145 additions and 27 deletions

View File

@@ -41,6 +41,7 @@ def restore_products(request, payload: List[ProductIn]):
defaults={
'description': item.description,
'default_net_weight': item.default_net_weight,
'requires_dates': item.requires_dates,
},
)
if was_created:
@@ -81,14 +82,22 @@ def list_orders(request, status: Optional[str] = Query(None)):
return qs
@api.post('/orders', response={201: OrderOut}, tags=['Orders'])
@api.post('/orders', response={201: OrderOut, 400: dict}, tags=['Orders'])
def create_order(request, payload: OrderIn):
product = get_object_or_404(Product, id=payload.product_id)
if product.requires_dates:
if not payload.production_date or not payload.next_control_date:
return 400, {'detail': 'production_date and next_control_date are required'}
production_date = payload.production_date
next_control_date = payload.next_control_date
else:
production_date = None
next_control_date = None
order = Order(
product=product,
batch_number=payload.batch_number,
production_date=payload.production_date,
next_control_date=payload.next_control_date,
production_date=production_date,
next_control_date=next_control_date,
total_weight=payload.total_weight,
canister_weight=payload.canister_weight,
canisters_per_box=payload.canisters_per_box,