fix: Prova OK gives the parent its Prumo final and queues it (0.1)
The proof answer is the parent's check: every ready full print file Prumo generated becomes an active final, and the parent enters Arte conferida. Items that still need hand preparation stay in Arte recebida.
This commit is contained in:
@@ -6,7 +6,7 @@ import secrets
|
||||
from decimal import Decimal
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
from typing import Literal
|
||||
from uuid import UUID
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response
|
||||
from fastapi.responses import RedirectResponse
|
||||
@@ -808,7 +808,23 @@ def proof_answer(uid: UUID, body: ProofAnswer, user=Depends(can('proof'))):
|
||||
c.execute('''INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason)
|
||||
VALUES(%s,'rev','fin',%s,%s)''', (uid, user, label))
|
||||
if body.result == 'ok':
|
||||
# The order enters the queue: Arte conferida, if its finals are approved.
|
||||
# A prova aprovada é a conferência do pai: os arquivos completos
|
||||
# que o Prumo gerou entram como finais, e o pai segue para a fila.
|
||||
# Itens que ainda dependem de preparo manual continuam em Arte
|
||||
# recebida, com o botão de final disponível.
|
||||
if parent['state'] == 'rec':
|
||||
generated = c.execute('''SELECT p.item_index,p.upload_id FROM dtf_local.print_files p
|
||||
WHERE p.order_id=%s AND p.status='ready' AND p.upload_id IS NOT NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM dtf_local.order_files f
|
||||
WHERE f.order_id=p.order_id AND f.item_index=p.item_index
|
||||
AND f.kind='final' AND f.active)
|
||||
ORDER BY p.item_index''', (parent['id'],)).fetchall()
|
||||
for row in generated:
|
||||
c.execute('''INSERT INTO dtf_local.order_files
|
||||
(id,order_id,upload_id,item_index,kind,note,created_by)
|
||||
VALUES(%s,%s,%s,%s,'final',%s,'Prumo')''',
|
||||
(uuid4(), parent['id'], row['upload_id'], row['item_index'],
|
||||
f'Aprovado pela prova do #{card["number"]}'))
|
||||
ready = parent['state'] == 'rec' and all(c.execute('''SELECT 1 FROM dtf_local.order_files
|
||||
WHERE order_id=%s AND kind='final' AND active AND item_index=%s LIMIT 1''', (parent['id'], i)).fetchone()
|
||||
for i in range(len(parent['snapshot']['items'])))
|
||||
|
||||
@@ -275,6 +275,34 @@ def run():
|
||||
assert mine['proof_ok_at'] and mine['proof_card']['proof_result'] == 'ok' and mine['state'] == 'tra', mine
|
||||
print('PASS: an order with a proof waits for its proof card, which is answered OK or rejected in Revisão')
|
||||
|
||||
# Prova OK is the parent's check: the full print file Prumo already made
|
||||
# becomes the parent final and the parent enters Arte conferida (0.1).
|
||||
readable = upload_bytes(client, artwork(), name='LOCAL-PROOF-REAL.png')
|
||||
long = loose_item(readable, copies=1)
|
||||
parent = paid_order(client, long)
|
||||
# A proof card for a small order, as the panel can open one; the parent
|
||||
# file is only 10 cm tall, so this test does not draw a 10 m film.
|
||||
with db.connect() as c:
|
||||
c.execute("UPDATE dtf_local.orders SET snapshot=jsonb_set(snapshot,'{proof}','true') WHERE id=%s",
|
||||
(parent['id'],))
|
||||
client.call('/operator/orders/' + parent['id'] + '/proof-card', {}, operator=True)
|
||||
board = client.call('/operator/board', operator=True)['orders']
|
||||
mine = next(o for o in board if o['id'] == parent['id'])
|
||||
card = next(o for o in board if o['id'] == mine['proof_card']['id'])
|
||||
wait_print(client, parent['id'], 'ready')
|
||||
wait_print(client, card['id'], 'ready')
|
||||
with db.connect() as c:
|
||||
c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s", (card['id'],))
|
||||
client.call('/operator/orders/' + card['id'] + '/proof-answer', {'result': 'ok'}, operator=True)
|
||||
mine = next(o for o in client.call('/operator/board', operator=True)['orders'] if o['id'] == parent['id'])
|
||||
assert mine['state'] == 'tra' and mine['final_items'] == [0], mine
|
||||
assert mine['proof_ok_at'] and mine['proof_card']['proof_result'] == 'ok', mine
|
||||
with db.connect() as c:
|
||||
final = c.execute('''SELECT note,created_by FROM dtf_local.order_files
|
||||
WHERE order_id=%s AND kind='final' AND active''', (parent['id'],)).fetchone()
|
||||
assert final['created_by'] == 'Prumo' and 'prova' in final['note'].lower(), final
|
||||
print('PASS: Prova OK turns Prumo\'s full file into the parent final and queues it')
|
||||
|
||||
# A customer cannot see or reuse another order's generated file.
|
||||
other = Client()
|
||||
other.call('/session')
|
||||
|
||||
Reference in New Issue
Block a user