feat: Kanban columns are queues, and a card can be dragged up or down
Some checks failed
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Failing after 3m24s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Has been skipped
Some checks failed
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Failing after 3m24s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Has been skipped
Each column is sorted explicitly by payment time, first paid on top, however the board's list was put together (older finished orders, one opened from the search). A card dragged within its column lands between the two it was dropped between (queue_key, halfway between their keys) and keeps that place for everyone; moving to another stage clears it. Reordering is not activity: the stalled clock keeps running. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ from fastapi.responses import RedirectResponse
|
||||
from ..core import db
|
||||
from ..core.auth import (COOKIE_SECURE, DUMMY_PASSWORD_HASH, audit, client_ip, operator,
|
||||
login_failed, password_matches, throttle)
|
||||
from ..core.models import Move, OperatorLogin, Resolution, Review
|
||||
from ..core.models import Move, OperatorLogin, Resolution, Review, StrictModel
|
||||
from ..printjobs import queue as queue_print_files
|
||||
from .. import payments, quote_review
|
||||
from .. import tiny
|
||||
@@ -402,6 +402,46 @@ def cancel_order(uid: UUID, body: Resolution, user=Depends(operator)):
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
class QueuePlace(StrictModel):
|
||||
"""Where a dragged card lands: between two orders of its column, either
|
||||
of them absent at the top or the bottom."""
|
||||
after: UUID | None = None
|
||||
before: UUID | None = None
|
||||
|
||||
|
||||
QUEUE_KEY = 'COALESCE(queue_key, extract(epoch FROM created_at))'
|
||||
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/queue')
|
||||
def queue_place(uid: UUID, body: QueuePlace, user=Depends(operator)):
|
||||
"""An order's place in its column: by default its payment time; dragged,
|
||||
halfway between the orders it was dropped between. It neither changes the
|
||||
order's stage nor counts as activity (the stalled clock keeps running)."""
|
||||
if not body.after and not body.before:
|
||||
raise HTTPException(422, 'Informe entre quais pedidos ele fica.')
|
||||
with db.connect() as c:
|
||||
row = c.execute('SELECT state FROM dtf_local.orders WHERE id=%s FOR UPDATE', (uid,)).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, 'Order not found')
|
||||
keys = {}
|
||||
for side in ('after', 'before'):
|
||||
other = getattr(body, side)
|
||||
if other:
|
||||
near = c.execute(f'SELECT state, {QUEUE_KEY} AS key FROM dtf_local.orders WHERE id=%s', (other,)).fetchone()
|
||||
if not near or near['state'] != row['state']:
|
||||
raise HTTPException(409, 'Os pedidos mudaram de etapa. Clique em Atualizar.')
|
||||
keys[side] = float(near['key'])
|
||||
if 'after' in keys and 'before' in keys:
|
||||
key = (keys['after'] + keys['before']) / 2
|
||||
elif 'after' in keys:
|
||||
key = keys['after'] + 60
|
||||
else:
|
||||
key = keys['before'] - 60
|
||||
c.execute('UPDATE dtf_local.orders SET queue_key=%s WHERE id=%s', (key, uid))
|
||||
audit('order_queue_moved', order=str(uid), operator=user)
|
||||
return {'ok': True, 'queue_key': key}
|
||||
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/move')
|
||||
def move(uid: UUID, body: Move, user=Depends(operator)):
|
||||
with db.connect() as c:
|
||||
@@ -429,7 +469,7 @@ def move(uid: UUID, body: Move, user=Depends(operator)):
|
||||
c.execute("UPDATE dtf_local.order_files SET active=false WHERE order_id=%s AND kind='final'", (uid,))
|
||||
c.execute('INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason,back) VALUES(%s,%s,%s,%s,%s,%s)',
|
||||
(uid,row['state'],body.state,user,body.reason,back))
|
||||
changed = c.execute('UPDATE dtf_local.orders SET state=%s, version=version+1, updated_at=now() WHERE id=%s RETURNING *', (body.state,uid)).fetchone()
|
||||
changed = c.execute('UPDATE dtf_local.orders SET state=%s, version=version+1, updated_at=now(), queue_key=NULL WHERE id=%s RETURNING *', (body.state,uid)).fetchone()
|
||||
events = {'imp':'production_started','cor':'correction_needed','fin':'ready'}
|
||||
if body.state in events and not back and not payments.is_test(row):
|
||||
# "Production started" and "ready" reach the customer once per order,
|
||||
|
||||
@@ -222,3 +222,7 @@ ALTER TABLE dtf_local.quotes ADD COLUMN IF NOT EXISTS discarded_by text;
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS cancelled_at timestamptz;
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS cancelled_by text;
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS cancel_reason text;
|
||||
|
||||
-- An order's place in its column's queue, when an operator dragged it up or
|
||||
-- down. Empty means "by payment time"; it is cleared when the order moves on.
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS queue_key double precision;
|
||||
|
||||
Reference in New Issue
Block a user