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

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:
Cauê Faleiros
2026-10-16 18:45:23 -03:00
parent 1f2358c8b5
commit dbf1efc112
5 changed files with 77 additions and 13 deletions

View File

@@ -72,6 +72,12 @@ def run():
board = client.call('/operator/board', operator=True)
order = next(o for o in board['orders'] if o['id'] == str(paid_order))
assert order['cancelled_at'] and order['cancel_reason'] == 'Cliente desistiu'
# Tiny is told, once (app/tiny.py cancels it there while not invoiced).
with db.connect() as c:
told = c.execute("SELECT provider,payload FROM dtf_local.outbox WHERE event_key=%s",
(f'{paid_order}:cancelled:tiny',)).fetchall()
assert [(t['provider'], t['payload']['event'], t['payload']['reason']) for t in told] == \
[('tiny', 'cancelled', 'Cliente desistiu')], told
# The automatic folder hears it is cancelled, and so removes its files.
held = client.call('/operator/queue/folder', {'early': True, 'held': [str(paid_order)]}, operator=True)
assert held['states'] == {str(paid_order): 'cancelled'}, held['states']

View File

@@ -264,6 +264,37 @@ class TinyStatusTests(FakeTinyCase):
self.assertEqual(ready['status'], 'not-applicable')
self.assertEqual(self.calls, [])
@mock.patch.dict(os.environ, {'TINY_STATUS_UPDATES': 'true'})
def test_printing_is_preparando_envio_but_never_moves_an_invoiced_order_back(self):
sale = self.tiny.deliver('k1', PAID)
started = {**READY, 'event': 'production_started', 'order': PAID['order'], 'tiny_id': sale['tiny_id']}
moved = self.tiny.deliver('k2', started)
self.assertEqual((moved['status'], moved['situacao'], self.orders[0]['situacao']),
('status-updated', 'Preparando envio', 4))
self.orders[0]['situacao'] = 1 # the team invoiced it
self.assertEqual(self.tiny.deliver('k2', started)['status'], 'status-unchanged')
self.assertEqual(self.orders[0]['situacao'], 1)
@mock.patch.dict(os.environ, {'TINY_STATUS_UPDATES': 'true'})
def test_a_cancelled_order_is_cancelled_in_tiny_unless_invoiced(self):
self.tiny.deliver('k1', PAID)
cancelled = {**READY, 'event': 'cancelled', 'order': PAID['order']}
done = self.tiny.deliver('k3', cancelled)
self.assertEqual((done['status'], done['situacao'], self.orders[0]['situacao']),
('status-updated', 'Cancelada', 2))
self.orders[0]['situacao'] = 1
kept = self.tiny.deliver('k3', cancelled)
self.assertEqual((kept['status'], kept['situacao'], self.orders[0]['situacao']),
('status-unchanged', 'Faturada', 1))
def test_printing_and_cancelling_change_nothing_while_status_updates_are_off(self):
self.tiny.deliver('k1', PAID)
self.calls.clear()
for event in ('production_started', 'cancelled'):
self.assertEqual(self.tiny.deliver('k', {**READY, 'event': event, 'order': PAID['order']})['status'],
'not-applicable')
self.assertEqual(self.calls, [])
def test_pickup_orders_carry_the_pickup_forma_de_envio(self):
self.assertEqual(order_payload(PICKUP, 1)['transportador'], {'formaEnvio': {'id': 77}})
self.assertNotIn('transportador', order_payload(PAID, 1))