feat: Tiny follows printing and cancellation
Some checks failed
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Some checks failed
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
With TINY_STATUS_UPDATES on, an order entering Imprimindo becomes "Preparando envio" in Tiny, and a cancelled order "Cancelada", next to the "Aprovada" on payment and the pickup "Pronto para envio" there already. Neither sends a WhatsApp in the client's n8n. An order the team already moved further in Tiny is never moved back, and an invoiced one is not cancelled here: its nota fiscal is cancelled in Tiny. Cancelling a paid order now tells Tiny, which it did not before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -269,7 +269,7 @@ def payment_events(state: Literal['open','resolved','all'] = 'open',
|
||||
@router.get('/api/operator/events')
|
||||
def events(provider: Literal['tiny'] | None = None,
|
||||
status: Literal['delivered','queued','failing'] | None = None,
|
||||
event: Literal['payment_approved','production_started','correction_needed','ready'] | None = None,
|
||||
event: Literal['payment_approved','production_started','correction_needed','ready','cancelled'] | None = None,
|
||||
order: int | None = Query(default=None, ge=1), offset: int = Query(default=0, ge=0),
|
||||
limit: int = Query(default=20, ge=1, le=100), user=Depends(can('manage'))):
|
||||
"""The integration send log, newest first, filtered, by page with a total."""
|
||||
@@ -496,13 +496,20 @@ def release_files(c, uploads):
|
||||
@router.post('/api/operator/orders/{uid}/cancel')
|
||||
def cancel_order(uid: UUID, body: Resolution, user=Depends(can('manage'))):
|
||||
"""A paid order leaves the board but keeps its payment and history. Nothing
|
||||
is refunded here (that is done at the provider) and Tiny is not told."""
|
||||
is refunded here (that is done at the provider); Tiny is told, so the
|
||||
order is cancelled there too while it was not invoiced (app/tiny.py)."""
|
||||
with db.connect() as c:
|
||||
row = c.execute('''UPDATE dtf_local.orders SET cancelled_at=now(), cancelled_by=%s, cancel_reason=%s,
|
||||
version=version+1, updated_at=now() WHERE id=%s AND cancelled_at IS NULL RETURNING number''',
|
||||
version=version+1, updated_at=now() WHERE id=%s AND cancelled_at IS NULL RETURNING *''',
|
||||
(user, body.note, uid)).fetchone()
|
||||
if not row:
|
||||
raise HTTPException(404, 'Pedido não encontrado ou já cancelado.')
|
||||
if not payments.is_test(row):
|
||||
sale = c.execute("SELECT receipt FROM dtf_local.outbox WHERE event_key=%s AND delivered_at IS NOT NULL",
|
||||
(f'{uid}:paid:tiny',)).fetchone()
|
||||
enqueue(c, f'{uid}:cancelled:tiny', 'tiny',
|
||||
{'order_id': str(uid), 'number': row['number'], 'event': 'cancelled', 'reason': body.note,
|
||||
'order': row['snapshot'], 'tiny_id': ((sale or {}).get('receipt') or {}).get('tiny_id')})
|
||||
audit('order_cancelled', order=row['number'], operator=user)
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user