feat: Gestão moves a printing order to another machine with a reason; the new one resumes from the part being ripped (Rodada 5, D4)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -219,6 +219,9 @@ def with_print_files(c, orders):
|
||||
# clock leaves out the time a preview waited for the customer (D2).
|
||||
previews = c.execute('''SELECT order_id,number,sent_at,sent_by,decided_at,result,reason,decided_by
|
||||
FROM dtf_local.redesign_previews WHERE order_id=ANY(%s) ORDER BY order_id,number''', (ids,)).fetchall()
|
||||
# Each order's machine transfers, oldest first (Rodada 5, D4).
|
||||
transfers = c.execute('''SELECT order_id,from_name,to_name,reason,resumed_from,created_by,created_at
|
||||
FROM dtf_local.machine_transfers WHERE order_id=ANY(%s) ORDER BY id''', (ids,)).fetchall()
|
||||
# Where a printing order's files are in its machine's hot folder (item 10).
|
||||
hot = hotfolder.progress(c, [o['id'] for o in orders if o['state'] == 'imp'])
|
||||
# Orders the machine already printed: a reprint chooses which items go
|
||||
@@ -267,6 +270,9 @@ def with_print_files(c, orders):
|
||||
order['previews'] = [{k: row[k] for k in ('number', 'sent_at', 'sent_by', 'decided_at', 'result',
|
||||
'reason', 'decided_by')}
|
||||
for row in previews if row['order_id'] == order['id']]
|
||||
order['transfers'] = [{k: row[k] for k in ('from_name', 'to_name', 'reason', 'resumed_from',
|
||||
'created_by', 'created_at')}
|
||||
for row in transfers if row['order_id'] == order['id']]
|
||||
return assign_machines(c, orders)
|
||||
|
||||
|
||||
|
||||
@@ -133,6 +133,47 @@ def choose_machine(uid: UUID, body: MachineChoice, request: Request, user=Depend
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
class MachineTransfer(StrictModel):
|
||||
machine_id: UUID
|
||||
reason: str = Field(max_length=500)
|
||||
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/transfer')
|
||||
def transfer_machine(uid: UUID, body: MachineTransfer, user=Depends(can('manage'))):
|
||||
"""A card already in Imprimindo changes machine (Rodada 5, D4), by Gestão
|
||||
or an administrator and with its reason: the old machine keeps what Flexi
|
||||
already took, and the new one starts from the part it was ripping."""
|
||||
reason = ' '.join(body.reason.split())
|
||||
with db.connect() as c:
|
||||
current = c.execute('SELECT * FROM dtf_local.orders WHERE id=%s FOR UPDATE', (uid,)).fetchone()
|
||||
if not current:
|
||||
raise HTTPException(404, 'Pedido não encontrado.')
|
||||
if current['cancelled_at'] or current['state'] != 'imp':
|
||||
raise HTTPException(409, 'Só um pedido em Imprimindo muda de máquina por aqui.')
|
||||
if len(reason) < 3:
|
||||
raise HTTPException(422, 'Escreva o motivo da transferência.')
|
||||
target = c.execute('SELECT name,products,active FROM dtf_local.machines WHERE id=%s',
|
||||
(body.machine_id,)).fetchone()
|
||||
if not target or not target['active']:
|
||||
raise HTTPException(404, 'Máquina não encontrada ou desativada.')
|
||||
if body.machine_id == current['machine_id']:
|
||||
raise HTTPException(409, 'O pedido já está nessa máquina.')
|
||||
if machines.product_family(current) not in target['products']:
|
||||
raise HTTPException(409, f"A {target['name']} não imprime este produto.")
|
||||
from_name = (c.execute('SELECT name FROM dtf_local.machines WHERE id=%s',
|
||||
(current['machine_id'],)).fetchone() if current['machine_id'] else None)
|
||||
from_name = from_name and from_name['name']
|
||||
resumed = hotfolder.transfer(c, uid)
|
||||
c.execute('UPDATE dtf_local.orders SET machine_id=%s, machine_chosen=true WHERE id=%s',
|
||||
(body.machine_id, uid))
|
||||
c.execute('''INSERT INTO dtf_local.machine_transfers(order_id,from_machine,to_machine,from_name,to_name,
|
||||
reason,resumed_from,created_by) VALUES(%s,%s,%s,%s,%s,%s,%s,%s)''',
|
||||
(uid, current['machine_id'], body.machine_id, from_name, target['name'], reason, resumed, user))
|
||||
audit('order_machine_transferred', order=current['number'], from_machine=str(current['machine_id'] or ''),
|
||||
to_machine=str(body.machine_id), operator=user)
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
@router.post('/api/operator/orders/{uid}/contraction')
|
||||
def choose_contraction(uid: UUID, body: Contraction, user=Depends(can('produce'))):
|
||||
"""The contraction class of an item (Dropstar, 2026-10-30): the browser's
|
||||
|
||||
Reference in New Issue
Block a user