feat: the pickup receipt in Recibos/ and "Retirado" on the card (Dropstar's third round, item 14)
All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 3m38s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 59s

A pickup order reaching Finalizado has its receipt due: a PDF for the
80 mm roll with the order number large at the top, the customer and
CPF/CNPJ, each product and its metres, the amount and how it was paid,
the date issued, and the "Retirado em" and "Assinatura" lines
(app/receipt.py). The Kanban's folder saves it in Recibos/, where the
counter's print queue sends it to the Bematech. One computer claims each
receipt on the server before writing it, so it is never printed twice,
and gives it back if it could not save it. Orders sent by carrier have
none.

"Retirado" on a pickup in Finalizado records when and who handed it
over, with an optional photo of the signed receipt (kept 30 days). Anyone
but the seller may mark it (new "deliver" capability); the order panel
also opens the receipt to print it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-29 18:39:17 -03:00
parent a5417d200e
commit d962865944
8 changed files with 378 additions and 14 deletions

View File

@@ -3,7 +3,9 @@
Run inside the API container: python -m tests.users_test
"""
import secrets
import time
from decimal import Decimal
from urllib.request import Request, urlopen
from uuid import uuid4
from psycopg.types.json import Jsonb
@@ -11,7 +13,7 @@ from psycopg.types.json import Jsonb
from app import machines as routing
from app import payments, proof
from app.core import db
from tests.smoke_test import Client
from tests.smoke_test import BASE, Client, with_host
PASSWORD = 'senha-de-teste-123'
@@ -39,6 +41,26 @@ def order_fixture(c, owner, mode, metres='1', printed=None):
return quote, order
def raw(client, path):
"""A response's bytes, for what is not JSON (the receipt's PDF)."""
with client.opener.open(Request(BASE + '/api' + path, headers=with_host()), timeout=30) as response:
return response.read()
def pickup_photo(client, oid, content):
"""The photo of a signed receipt, sent as the counter does, until scanned clean."""
uid = client.call(f'/operator/orders/{oid}/pickup-uploads', {'name': 'recibo.png', 'size': len(content)})['id']
url = client.call(f'/operator/uploads/{uid}/parts/1', {})['url']
with urlopen(Request(url, data=content, method='PUT'), timeout=30) as response:
assert response.status == 200
client.call(f'/operator/uploads/{uid}/complete', {})
deadline = time.monotonic() + 150
while client.call(f'/operator/uploads/{uid}')['scan_state'] != 'clean':
assert time.monotonic() < deadline, 'photo scan did not finish'
time.sleep(0.5)
return uid
def expected_machine(su, product, metres=1.0):
"""What app/machines.py should pick now: the active machine of the product
with the fewest metres open, among those with room, else among all."""
@@ -161,17 +183,41 @@ def run():
'password': PASSWORD})
reviewer = signed_in(emails['revisor'])
me = reviewer.call('/operator/me')
assert me['can'] == ['view'] and sorted(me['moves']) == [['fin', 'rev'], ['rev', 'fin']] and me['reorder'] == ['rev'], me
assert me['can'] == ['deliver', 'view'] and sorted(me['moves']) == [['fin', 'rev'], ['rev', 'fin']] and me['reorder'] == ['rev'], me
reviewer.call(f'/operator/orders/{textil_o}/move', {'state': 'tra', 'version': 0, 'reason': ''}, expected=403)
assert reviewer.call(f'/operator/orders/{uv_o}/move', {'state': 'fin', 'version': printed['version'],
'reason': ''})['state'] == 'fin'
# A pickup in Finalizado has its receipt (item 14): 80 mm wide, saved
# in Recibos/ by one computer only, and printed again from the panel.
pdf = raw(su.operator_client, f'/operator/orders/{uv_o}/receipt')
assert pdf.startswith(b'%PDF') and b'/MediaBox [0 0 226.7717 ' in pdf, pdf[:200]
due = lambda: {r['order']: r['name'] for r in su.call('/operator/queue/folder', {'early': True}, operator=True)['receipts']}
number = next(o for o in su.call('/operator/board', operator=True)['orders'] if o['id'] == str(uv_o))['number']
assert due()[str(uv_o)] == f'Recibo-DTF-{number}.pdf'
su.call(f'/operator/orders/{uv_o}/receipt/claim', {}, operator=True)
su.call(f'/operator/orders/{uv_o}/receipt/claim', {}, operator=True, expected=409)
assert str(uv_o) not in due()
# Not saved after all: it goes back for another computer to take.
su.call(f'/operator/orders/{uv_o}/receipt/release', {}, operator=True)
assert str(uv_o) in due()
su.call(f'/operator/orders/{uv_o}/receipt/claim', {}, operator=True)
# "Retirado": anyone but the seller, only in Finalizado, once, with the
# photo of the signed receipt.
seller.call(f'/operator/orders/{uv_o}/picked-up', {}, expected=403)
reviewer.call(f'/operator/orders/{textil_o}/picked-up', {}, expected=409)
png = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR' + (40).to_bytes(4, 'big') + (60).to_bytes(4, 'big') + b'\x08\x06\x00\x00\x00' + b'\x00' * 4
photo = pickup_photo(reviewer, uv_o, png)
reviewer.call(f'/operator/orders/{uv_o}/picked-up', {'photo': photo})
reviewer.call(f'/operator/orders/{uv_o}/picked-up', {}, expected=409)
shown = next(o for o in su.call('/operator/board', operator=True)['orders'] if o['id'] == str(uv_o))
assert (shown['picked_up_by'], shown['picked_up_photo']) == (emails['revisor'], photo) and shown['picked_up_at'], shown
# The designer: every order, whatever its machine; the artwork stages only.
admin.call('/operator/users', {'name': 'Arte', 'email': emails['designer'], 'role': 'designer',
'password': PASSWORD, 'machines': [uv]})
assert next(u for u in admin.call('/operator/users')['users'] if u['email'] == emails['designer'])['machines'] == []
designer = signed_in(emails['designer'])
assert set(designer.call('/operator/me')['can']) == {'view', 'produce'}
assert set(designer.call('/operator/me')['can']) == {'view', 'produce', 'deliver'}
designer.call(f'/operator/quotes/{uv_q}/register', {'origin': 'atendimento', 'method': 'pix'}, expected=403)
assert {str(uv_o), str(textil_o)} <= {o['id'] for o in designer.call('/operator/board')['orders']}
version = next(o for o in designer.call('/operator/board')['orders'] if o['id'] == str(textil_o))['version']