feat: the folder can download as the order arrives, and removes cancelled orders' files
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 5m5s
Build and deploy / Secret scan and release gate (push) Successful in 11s
Build and deploy / Publish images (push) Successful in 1m23s
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 5m5s
Build and deploy / Secret scan and release gate (push) Successful in 11s
Build and deploy / Publish images (push) Successful in 1m23s
Integrações gets "Baixar ao chegar" next to "Baixar na Fila". On arrival the file (the generated print file, or the final once approved) goes into a Recebidos folder inside the chosen one and moves up when the order enters the queue. Files of orders cancelled, deleted or sent back for correction, and files replaced by another final, leave the folder. The launch reset now restarts order numbers at #1 by itself: the worker's role may set the orders' number sequence, and nothing else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -793,21 +793,9 @@ def production_stats(days: int = Query(default=30, ge=7, le=365), user=Depends(o
|
||||
'waiting': {row['state']: {'orders': row['orders'], 'oldest_hours': hours(row['oldest_hours'])} for row in waiting}}
|
||||
|
||||
|
||||
@router.get('/api/operator/queue/finals')
|
||||
def queue_finals(request: Request, auto: bool = False, user=Depends(can('produce'))):
|
||||
"""The approved final files of every order in the print queue, in queue
|
||||
order, each named after its order so a folder of them stays readable. The
|
||||
browser downloads them straight from storage: a zip of multi-GB sheets
|
||||
would go through the server."""
|
||||
with db.connect() as c:
|
||||
rows = c.execute(f'''SELECT o.number,f.item_index,f.upload_id,u.object_key,u.name FROM dtf_local.orders o
|
||||
JOIN dtf_local.order_files f ON f.order_id=o.id JOIN dtf_local.uploads u ON u.id=f.upload_id
|
||||
WHERE o.state='fil' AND o.cancelled_at IS NULL AND {FINAL_OK}
|
||||
ORDER BY COALESCE(o.queue_key, extract(epoch FROM o.created_at)),o.id,f.item_index,f.created_at''').fetchall()
|
||||
# A machine's operator downloads only that machine's queue.
|
||||
queued = assign_machines(c, c.execute("SELECT * FROM dtf_local.orders WHERE state='fil' AND cancelled_at IS NULL").fetchall())
|
||||
mine = {o['number'] for o in visible(request, queued)}
|
||||
rows = [row for row in rows if row['number'] in mine]
|
||||
def named_files(rows):
|
||||
"""Each file named after its order and item, so a folder of them stays
|
||||
readable, with a link straight to storage."""
|
||||
files, names = [], set()
|
||||
for row in rows:
|
||||
prefix = f"pedido-{row['number']}-item-{row['item_index'] + 1}"
|
||||
@@ -818,14 +806,72 @@ def queue_finals(request: Request, auto: bool = False, user=Depends(can('produce
|
||||
name = f'{stem} ({copy}).{ext}' if dot else f'{ext} ({copy})'
|
||||
copy += 1
|
||||
names.add(name)
|
||||
files.append({'number': row['number'], 'item': row['item_index'] + 1, 'name': name,
|
||||
'upload_id': str(row['upload_id']), 'url': storage.download(row['object_key'], name)})
|
||||
files.append({'order': str(row['order_id']), 'state': row['state'], 'number': row['number'],
|
||||
'item': row['item_index'] + 1, 'name': name, 'upload_id': str(row['upload_id']),
|
||||
'url': storage.download(row['object_key'], name)})
|
||||
return files
|
||||
|
||||
|
||||
def print_ready(c, request, states):
|
||||
"""The file to print for each item of the orders in these stages, in queue
|
||||
order: the approved final, or before approval the generated print file
|
||||
(unless the customer has sent a correction since). An operator who works
|
||||
on some machines gets only those machines' orders."""
|
||||
rows = c.execute(f'''SELECT o.id AS order_id,o.state,o.number,f.item_index,f.upload_id,u.object_key,u.name,
|
||||
COALESCE(o.queue_key, extract(epoch FROM o.created_at)) AS position
|
||||
FROM dtf_local.orders o
|
||||
JOIN dtf_local.order_files f ON f.order_id=o.id JOIN dtf_local.uploads u ON u.id=f.upload_id
|
||||
WHERE o.state=ANY(%s) AND o.cancelled_at IS NULL AND {FINAL_OK}
|
||||
UNION ALL
|
||||
SELECT o.id,o.state,o.number,p.item_index,p.upload_id,u.object_key,u.name,
|
||||
COALESCE(o.queue_key, extract(epoch FROM o.created_at))
|
||||
FROM dtf_local.orders o
|
||||
JOIN dtf_local.print_files p ON p.order_id=o.id JOIN dtf_local.uploads u ON u.id=p.upload_id
|
||||
WHERE o.state=ANY(%s) AND o.state IN ('rec','tra') AND o.cancelled_at IS NULL AND p.status='ready'
|
||||
AND u.expires_at>now() AND u.purged_at IS NULL AND u.scan_state='clean'
|
||||
AND NOT EXISTS (SELECT 1 FROM dtf_local.order_files f WHERE f.order_id=o.id AND f.kind='final'
|
||||
AND f.active AND f.item_index=p.item_index)
|
||||
AND NOT EXISTS (SELECT 1 FROM dtf_local.order_files f WHERE f.order_id=o.id AND f.kind='correction')
|
||||
ORDER BY position,order_id,item_index''', (list(states), list(states))).fetchall()
|
||||
staged = assign_machines(c, c.execute('''SELECT * FROM dtf_local.orders
|
||||
WHERE state=ANY(%s) AND cancelled_at IS NULL''', (list(states),)).fetchall())
|
||||
mine = {o['id'] for o in visible(request, staged)}
|
||||
return [row for row in rows if row['order_id'] in mine]
|
||||
|
||||
|
||||
@router.get('/api/operator/queue/finals')
|
||||
def queue_finals(request: Request, auto: bool = False, user=Depends(can('produce'))):
|
||||
"""The approved final files of every order in the print queue. The browser
|
||||
downloads them straight from storage: a zip of multi-GB sheets would go
|
||||
through the server."""
|
||||
with db.connect() as c:
|
||||
files = named_files(print_ready(c, request, ('fil',)))
|
||||
# The automatic folder asks whenever the queue changes; only a person's download is logged.
|
||||
if not auto:
|
||||
audit('queue_finals_downloaded', operator=user, files=len(files))
|
||||
return {'files': files}
|
||||
|
||||
|
||||
class FolderSync(StrictModel):
|
||||
early: bool = False
|
||||
held: list[UUID] = Field(default_factory=list, max_length=1000)
|
||||
|
||||
|
||||
@router.post('/api/operator/queue/folder')
|
||||
def queue_folder(body: FolderSync, request: Request, user=Depends(can('produce'))):
|
||||
"""What the Kanban's automatic folder should hold. Early, it also gets the
|
||||
files of orders just received (to a "Recebidos" folder), so a large sheet is
|
||||
already on the computer when the order reaches the queue. `states` answers
|
||||
for the orders the folder already holds files of: a stage, 'cancelled', or
|
||||
nothing when the order was deleted, so their files can be removed."""
|
||||
with db.connect() as c:
|
||||
files = named_files(print_ready(c, request, ('rec', 'tra', 'fil') if body.early else ('fil',)))
|
||||
held = c.execute('SELECT id,state,cancelled_at FROM dtf_local.orders WHERE id=ANY(%s)',
|
||||
(body.held,)).fetchall() if body.held else []
|
||||
return {'files': files,
|
||||
'states': {str(o['id']): 'cancelled' if o['cancelled_at'] else o['state'] for o in held}}
|
||||
|
||||
|
||||
@router.get('/api/operator/uploads/{uid}/download')
|
||||
def download(uid: UUID, user=Depends(operator)):
|
||||
with db.connect() as c:
|
||||
|
||||
Reference in New Issue
Block a user