feat: a reprint sends only the items chosen to the machine (Marcus, 2026-11-26, #105)
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 7m55s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m34s
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 7m55s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m34s
An order the machine already printed, back in Arte conferida, sends again only the items whose final changed since the machine took them; the panel's "Vai para a máquina" shows and changes the choice, and the card says "Reimpressão". The order stays one card. The pass to Revisão keeps the items printed, so the machine's metres count only those. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -504,8 +504,24 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
if body.state == 'imp' and row['machine_id']:
|
||||
machine_name = (c.execute('SELECT name FROM dtf_local.machines WHERE id=%s',
|
||||
(row['machine_id'],)).fetchone() or {}).get('name')
|
||||
c.execute('''INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason,back,machine)
|
||||
VALUES(%s,%s,%s,%s,%s,%s,%s)''', (uid,row['state'],body.state,user,body.reason,back,machine_name))
|
||||
# A pass from Imprimindo to Revisão keeps the items it printed, when
|
||||
# only some went again (machine_log counts their metres).
|
||||
printed_items = row.get('print_items') if row['state'] == 'imp' and body.state == 'rev' and not back else None
|
||||
c.execute('''INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason,back,machine,items)
|
||||
VALUES(%s,%s,%s,%s,%s,%s,%s,%s)''', (uid,row['state'],body.state,user,body.reason,back,machine_name,printed_items))
|
||||
# Back in the queue after a print: only the items whose final changed
|
||||
# go to the machine again, unless the team already chose (#105).
|
||||
if body.state == 'tra' and not back and row.get('print_items') is None:
|
||||
taken = hotfolder.printed(c, [uid]).get(uid)
|
||||
if taken:
|
||||
finals = [(r['item_index'], r['upload_id']) for r in c.execute('''SELECT item_index,upload_id
|
||||
FROM dtf_local.order_files WHERE order_id=%s AND kind='final' AND active''', (uid,)).fetchall()]
|
||||
default = hotfolder.reprint_default(finals, taken, len(row['snapshot']['items']))
|
||||
if default:
|
||||
c.execute('UPDATE dtf_local.orders SET print_items=%s WHERE id=%s', (default, uid))
|
||||
# Finished: the next time it goes back, the choice starts over.
|
||||
if body.state == 'fin' and not back:
|
||||
c.execute('UPDATE dtf_local.orders SET print_items=NULL WHERE id=%s', (uid,))
|
||||
# Pulled to Imprimindo, its files go to its machine's hot folder; out
|
||||
# of it, what Flexi did not take leaves (item 10).
|
||||
if row['state'] == 'imp':
|
||||
@@ -537,6 +553,32 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
enqueue(c, key, 'tiny', tiny)
|
||||
return changed
|
||||
|
||||
class PrintItems(StrictModel):
|
||||
items: list[int] = Field(min_length=1, max_length=200)
|
||||
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/print-items')
|
||||
def choose_print_items(uid: UUID, body: PrintItems, user=Depends(can('produce'))):
|
||||
"""Which items go to the machine this time (Marcus, 2026-11-26, #105):
|
||||
a reprint sends only those. Every item: all go, as on the first print."""
|
||||
with db.connect() as c:
|
||||
row = c.execute('SELECT id,number,state,snapshot,cancelled_at FROM dtf_local.orders WHERE id=%s FOR UPDATE',
|
||||
(uid,)).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, 'Pedido não encontrado.')
|
||||
if row['cancelled_at'] or row['state'] not in ('rec', 'tra', 'cor'):
|
||||
raise HTTPException(409, 'Os itens que vão para a máquina são escolhidos antes de Imprimindo.')
|
||||
count = len(row['snapshot']['items'])
|
||||
items = sorted(set(body.items))
|
||||
if any(i < 0 or i >= count for i in items):
|
||||
raise HTTPException(422, 'Item do pedido inválido.')
|
||||
chosen = None if len(items) == count else items
|
||||
c.execute('UPDATE dtf_local.orders SET print_items=%s, version=version+1, updated_at=now() WHERE id=%s',
|
||||
(chosen, uid))
|
||||
audit('order_print_items', order=row['number'], items=','.join(str(i + 1) for i in items), operator=user)
|
||||
return {'ok': True, 'print_items': chosen}
|
||||
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/print-files')
|
||||
def regenerate(uid: UUID, user=Depends(can('produce'))):
|
||||
"""Queue generation again for items that failed or went to manual preparation,
|
||||
|
||||
Reference in New Issue
Block a user