Allow zero canister or box count, but not both
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
10
slips/api.py
10
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 payload.canister_count is not None or payload.box_count is not None:
|
||||||
if order.status != 'pending':
|
if order.status != 'pending':
|
||||||
return 400, {'detail': 'Only pending orders can change label counts'}
|
return 400, {'detail': 'Only pending orders can change label counts'}
|
||||||
if payload.canister_count is not None and payload.canister_count < 1:
|
cc = payload.canister_count if payload.canister_count is not None else order.canister_count
|
||||||
return 400, {'detail': 'canister_count must be >= 1'}
|
bc = payload.box_count if payload.box_count is not None else order.box_count
|
||||||
if payload.box_count is not None and payload.box_count < 1:
|
if cc < 0 or bc < 0:
|
||||||
return 400, {'detail': 'box_count must be >= 1'}
|
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)
|
order.set_counts(payload.canister_count, payload.box_count)
|
||||||
|
|
||||||
if payload.status is not None:
|
if payload.status is not None:
|
||||||
|
|||||||
@@ -174,10 +174,14 @@ function showToast(message, isError = false) {
|
|||||||
|
|
||||||
async function adjustCount(id, field, delta) {
|
async function adjustCount(id, field, delta) {
|
||||||
const spanId = field === 'canister_count' ? `cc-${id}` : `bc-${id}`;
|
const spanId = field === 'canister_count' ? `cc-${id}` : `bc-${id}`;
|
||||||
|
const otherId = field === 'canister_count' ? `bc-${id}` : `cc-${id}`;
|
||||||
const span = document.getElementById(spanId);
|
const span = document.getElementById(spanId);
|
||||||
if (!span) return;
|
if (!span) return;
|
||||||
const next = parseInt(span.textContent, 10) + delta;
|
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 {
|
try {
|
||||||
const res = await fetch(`/api/orders/${id}`, {
|
const res = await fetch(`/api/orders/${id}`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user