feat: the orders' files in Dropstar's three folders: Arte recebida, Arte conferida, Finalizado
All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 4m27s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m19s

Asked by Dropstar on 2026-10-23 and agreed on 2026-10-26. The automatic
folder becomes "Pastas dos pedidos": one main folder is chosen once, in
Chrome or Edge on a factory computer that reaches the server, and the
Kanban keeps three folders inside it, moved with the card.

- Arte recebida: the order's file as soon as the order arrives
- Arte conferida: the queue; the file moves there with the card and stays
  while it prints and is checked in Revisão
- Finalizado: when the order is released, kept 30 days
- Correção, a cancellation or a deletion takes the file out; a replaced
  final is swapped
- orders already printing when the folder is chosen are not downloaded; a
  file someone took out comes back only when its order moves on, so the
  server now returns the files of orders the folders hold while they print,
  are checked and finish
- Firefox, which cannot write into folders, still only downloads the files
  entering Arte conferida

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-26 16:31:20 -03:00
parent b6f20733fa
commit ee1159065a
5 changed files with 170 additions and 138 deletions

View File

@@ -945,29 +945,32 @@ def named_files(rows):
return files
def print_ready(c, request, states):
def print_ready(c, request, states, only=None):
"""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."""
(unless the customer has sent a correction since). `only` narrows it to
these orders. An operator who works on some machines gets only those
machines' orders."""
ids = None if only is None else list(only)
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}
WHERE o.state=ANY(%s) AND (%s::uuid[] IS NULL OR o.id=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'
WHERE o.state=ANY(%s) AND (%s::uuid[] IS NULL OR o.id=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()
ORDER BY position,order_id,item_index''', (list(states), ids, ids, list(states), ids, ids)).fetchall()
staged = assign_machines(c, c.execute('''SELECT * FROM dtf_local.orders
WHERE state=ANY(%s) AND cancelled_at IS NULL''', (list(states),)).fetchall())
WHERE state=ANY(%s) AND (%s::uuid[] IS NULL OR id=ANY(%s)) AND cancelled_at IS NULL''',
(list(states), ids, ids)).fetchall())
mine = {o['id'] for o in visible(request, staged)}
return [row for row in rows if row['order_id'] in mine]
@@ -992,13 +995,19 @@ class FolderSync(StrictModel):
@router.post('/api/operator/queue/folder')
def queue_folder(body: FolderSync, request: Request, user=Depends(can('print'))):
"""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."""
"""What the Kanban's automatic folders should hold. `early` is Dropstar's
three folders (2026-10-26): the files of orders in Arte recebida and Arte
conferida, and, for the orders the folders already hold, their files while
they print, are checked in Revisão and sit in Finalizado, so one taken out
of a folder can be fetched again when the order moves on. Without it, only
the queue's (Firefox's downloads). `states` answers for the orders the
folders hold 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') if body.early else ('tra',)))
rows = print_ready(c, request, ('rec', 'tra') if body.early else ('tra',))
if body.early and body.held:
rows += print_ready(c, request, ('imp', 'rev', 'fin'), only=body.held)
files = named_files(rows)
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,