feat: a cancelled order can be deleted
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 2m55s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m2s

"Excluir pedido" now also works on a paid order once it is cancelled; one in
progress must be cancelled first, with its reason. Deleting a cancelled order
also discards its quote, so it neither returns to Cotações as unpaid nor can
be paid again. The payment stays recorded and the audit log keeps who deleted
which order and the cancellation reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-02 16:32:26 -03:00
parent dfa297d9b5
commit 8236ad8f0a
3 changed files with 32 additions and 12 deletions

View File

@@ -45,14 +45,15 @@ def run():
# A test order is deleted, and its quote is unpaid again.
test_order = client.call(f'/operator/quotes/{test_quote}/test-order', {}, operator=True)['id']
assert str(test_quote) not in listed()
client.call(f'/operator/orders/{test_order}/delete-test', {}, operator=True)
client.call(f'/operator/orders/{test_order}/delete', {}, operator=True)
with db.connect() as c:
assert not c.execute('SELECT 1 FROM dtf_local.orders WHERE id=%s', (test_order,)).fetchone()
test_order = None
assert str(test_quote) in listed()
# A paid order is cancelled with a reason, kept, and can no longer move.
client.call(f'/operator/orders/{paid_order}/delete-test', {}, operator=True, expected=409)
# A paid order in progress is not deleted: it is cancelled first.
client.call(f'/operator/orders/{paid_order}/delete', {}, operator=True, expected=409)
client.call(f'/operator/orders/{paid_order}/cancel', {'note': 'x'}, operator=True, expected=422)
client.call(f'/operator/orders/{paid_order}/cancel', {'note': 'Cliente desistiu'}, operator=True)
board = client.call('/operator/board', operator=True)
@@ -61,7 +62,14 @@ def run():
client.call(f'/operator/orders/{paid_order}/move', {'state': 'tra', 'version': order['version'], 'reason': ''},
operator=True, expected=409)
client.call(f'/operator/orders/{paid_order}/cancel', {'note': 'de novo'}, operator=True, expected=404)
print('PASS: discard hides and blocks a quote; test orders delete; paid orders cancel and stay')
# Cancelled, it can be deleted; its quote is discarded, not unpaid again.
client.call(f'/operator/orders/{paid_order}/delete', {}, operator=True)
with db.connect() as c:
assert not c.execute('SELECT 1 FROM dtf_local.orders WHERE id=%s', (paid_order,)).fetchone()
assert c.execute('SELECT discarded_at FROM dtf_local.quotes WHERE id=%s', (paid_quote,)).fetchone()['discarded_at']
assert str(paid_quote) not in listed()
print('PASS: discard hides and blocks a quote; test orders delete; paid orders cancel, then delete')
finally:
with db.connect() as c:
for oid in filter(None, (test_order, paid_order)):