fix: a reprint keeps an all-items choice, an undone pass to Revisão prints nothing again, and Prova OK tells Tiny (#105)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m56s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m26s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m56s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m26s
- Every item ticked was saved as NULL, which also means "not chosen", so the pass to the queue replaced it with the suggestion and only the changed item went to the machine; the panel showed the suggestion again. The choice is now the whole list. - Undoing a pass to Revisão (back to Imprimindo) started a new round with every file, so FlexiPRINT printed the order again. It now writes back only what Flexi had not taken, and the reprint choice of that pass returns. A pass undone this way no longer counts its film twice in the machine's metres (machine log and Números). - An order entering the queue by Prova OK never sent Tiny's "Preparando envio". The stage's Tiny event is now one function, used by the move and by the Prova OK. Integration test follows the real moves: suggestion, all items kept, pull onto a machine, two undone passes to Revisão, metres counted once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -524,12 +524,20 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
# again from what changed since.
|
||||
if printed_items is not None or (body.state == 'fin' and not back):
|
||||
c.execute('UPDATE dtf_local.orders SET print_items=NULL WHERE id=%s', (uid,))
|
||||
# Back to Imprimindo from Revisão (a mistaken move undone): the items
|
||||
# that pass printed are the choice again, and only what Flexi had not
|
||||
# taken goes back to the folder, never the whole order.
|
||||
if body.state == 'imp' and back:
|
||||
undone = c.execute('''SELECT items FROM dtf_local.movements WHERE order_id=%s
|
||||
AND from_state='imp' AND to_state='rev' AND NOT back ORDER BY id DESC LIMIT 1''', (uid,)).fetchone()
|
||||
if undone and undone['items'] is not None:
|
||||
c.execute('UPDATE dtf_local.orders SET print_items=%s WHERE id=%s', (undone['items'], 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':
|
||||
hotfolder.stop(c, uid)
|
||||
if body.state == 'imp':
|
||||
hotfolder.start(c, uid)
|
||||
(hotfolder.resume if back else hotfolder.start)(c, uid)
|
||||
# A pickup reaching Finalizado has its receipt due (item 14), once.
|
||||
due = body.state == 'fin' and not back and receipt.is_pickup(row['snapshot'])
|
||||
changed = c.execute('''UPDATE dtf_local.orders SET state=%s, version=version+1, updated_at=now(),
|
||||
@@ -538,21 +546,8 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
WHERE id=%s RETURNING *''', (body.state, body.state, due, uid)).fetchone()
|
||||
# Entering the queue (Arte conferida) is Tiny's "Preparando envio";
|
||||
# Finalizado its "Pronto para envio" (Dropstar's flow, 2026-10-23).
|
||||
events = {'tra':'production_started','cor':'correction_needed','fin':'ready'}
|
||||
if body.state in events and not back and payments.in_tiny(row):
|
||||
# "Production started" and "ready" reach the customer once per order,
|
||||
# even if a mistaken move is undone and made again. Each correction
|
||||
# is a new request, so it keeps one message per movement.
|
||||
once = body.state in ('tra','fin')
|
||||
event = {'order_id':str(uid), 'number':row['number'], 'event':events[body.state], 'reason':body.reason,
|
||||
'customer_path': f'/portal.html?order={uid}'}
|
||||
# Tiny needs the order (customer, pickup or delivery) and, once the
|
||||
# sale reached it, its id, to set the situação without a search.
|
||||
sale = c.execute("SELECT receipt FROM dtf_local.outbox WHERE event_key=%s AND delivered_at IS NOT NULL",
|
||||
(f'{uid}:paid:tiny',)).fetchone()
|
||||
tiny = {**event, 'order': row['snapshot'], 'tiny_id': ((sale or {}).get('receipt') or {}).get('tiny_id')}
|
||||
key = f'{uid}:{events[body.state]}:tiny' if once else f'{uid}:{changed["version"]}:tiny'
|
||||
enqueue(c, key, 'tiny', tiny)
|
||||
if not back:
|
||||
payments.stage_event(c, row, body.state, body.reason, changed['version'])
|
||||
return changed
|
||||
|
||||
class PrintItems(StrictModel):
|
||||
@@ -574,7 +569,9 @@ def choose_print_items(uid: UUID, body: PrintItems, user=Depends(can('produce'))
|
||||
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
|
||||
# Every item is kept as the whole list, not NULL: NULL is "not chosen
|
||||
# yet", which the pass to the queue would replace with the suggestion.
|
||||
chosen = 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)
|
||||
|
||||
Reference in New Issue
Block a user