From a5cb3ef35fb4b5abb005b5d1b9c396212470ccd5 Mon Sep 17 00:00:00 2001 From: diaco Date: Tue, 20 Oct 2026 10:52:07 +0330 Subject: [PATCH] Allow zero canister or box count, but not both Co-authored-by: Cursor --- slips/api.py | 10 ++++++---- slips/static/slips/js/i18n.js | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/slips/api.py b/slips/api.py index e18456a..d4a98d5 100644 --- a/slips/api.py +++ b/slips/api.py @@ -114,10 +114,12 @@ def update_order(request, order_id: int, payload: OrderUpdateIn): 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'} + cc = payload.canister_count if payload.canister_count is not None else order.canister_count + bc = payload.box_count if payload.box_count is not None else order.box_count + if cc < 0 or bc < 0: + return 400, {'detail': 'counts must be >= 0'} + if cc == 0 and bc == 0: + return 400, {'detail': 'canister_count and box_count cannot both be 0'} order.set_counts(payload.canister_count, payload.box_count) if payload.status is not None: diff --git a/slips/static/slips/js/i18n.js b/slips/static/slips/js/i18n.js index 1880f21..07af732 100644 --- a/slips/static/slips/js/i18n.js +++ b/slips/static/slips/js/i18n.js @@ -174,10 +174,14 @@ function showToast(message, isError = false) { async function adjustCount(id, field, delta) { const spanId = field === 'canister_count' ? `cc-${id}` : `bc-${id}`; + const otherId = field === 'canister_count' ? `bc-${id}` : `cc-${id}`; const span = document.getElementById(spanId); if (!span) return; const next = parseInt(span.textContent, 10) + delta; - if (next < 1) return; + if (next < 0) return; + const other = document.getElementById(otherId); + const otherVal = other ? parseInt(other.textContent, 10) : 0; + if (next === 0 && otherVal === 0) return; try { const res = await fetch(`/api/orders/${id}`, {