Allow zero label counts; keep reprint weights stable #36

Merged
rhino merged 2 commits from cursor/allow-zero-label-counts into main 2026-10-20 07:38:39 +00:00
2 changed files with 11 additions and 5 deletions
Showing only changes of commit a5cb3ef35f - Show all commits

View File

@@ -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:

View File

@@ -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}`, {