feat: rework register, opened by Gestao with a locked cause and authorized by an Administrador (Dropstar's rules D-02 to D-04)
All checks were successful
Build and deploy / Validate source (push) Successful in 10s
Build and deploy / Integration suite on a real stack (push) Successful in 3m27s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m2s

Gestao opens a rework from the order panel with its cause (falha de
impressao, perfil de cor, erro de tratamento, erro de pedido, or arte
aprovada pelo cliente, outside the goal), the metres redone and a note; the
cause never changes. An Administrador authorizes or declines it with a
reason, never one they opened, and only an authorized rework counts. The
order keeps who printed it. Numeros shows the metres redone per cause over
the film printed, against 0,4% per cause and 1,6% for the house, by who
printed, and the reworks waiting for authorization. Vendedor goes back to
viewing only (D-30): registering orders paid outside is Administrador and
Gestao.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-27 13:09:56 -03:00
parent babd9e327c
commit 5692804c6f
8 changed files with 282 additions and 17 deletions

View File

@@ -152,10 +152,9 @@ def run():
seller.call(f'/operator/quotes/{uv_q}/discard', {}, expected=403)
seller.call(f'/operator/orders/{textil_o}/machine', {'machine_id': None}, expected=403)
seller.call(f'/operator/orders/{textil_o}/contact', {'waiting': True, 'note': 'Ligar'}, expected=403)
# The seller registers orders paid outside (D-35); this quote already has
# its order, so the answer is 409, past the permission.
assert seller.call('/operator/me')['can'] == ['enter', 'view']
seller.call(f'/operator/quotes/{uv_q}/register', {'origin': 'atendimento', 'method': 'pix'}, expected=409)
# The seller only views the board (D-30): no order registered by hand either.
assert seller.call('/operator/me')['can'] == ['view']
seller.call(f'/operator/quotes/{uv_q}/register', {'origin': 'atendimento', 'method': 'pix'}, expected=403)
# Only the Revisor releases to Finalizado: not even the administrator.
admin.call(f'/operator/orders/{uv_o}/move', {'state': 'fin', 'version': printed['version'], 'reason': ''},
expected=403)
@@ -333,6 +332,54 @@ def run():
board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']}
back = board[str(textil_o)]['machine']
assert back and back['id'] != uv and not back['chosen']
# Rework (D-02 to D-04): Gestão opens it with its cause, an Administrador
# authorizes it, never their own, and only then it counts in Números.
emails['gestao'] = f'gestao-{tag}@example.test'
admin.call('/operator/users', {'name': 'Mayana', 'email': emails['gestao'], 'role': 'gestao', 'password': PASSWORD})
coord = signed_in(emails['gestao'])
with db.connect() as c:
c.execute('UPDATE dtf_local.orders SET payment=%s WHERE id=%s',
(Jsonb({'provider': 'mercadopago', 'id': f'rework-{tag}'}), uv_o))
figures = lambda: admin.call('/operator/stats?days=7')['rework']
cause = lambda figures, name: next(r for r in figures['causes'] if r['cause'] == name)['metres']
before = figures()
coord.call(f'/operator/orders/{uv_o}/reworks', {'cause': 'outra', 'metres': '1'}, expected=422)
coord.call(f'/operator/orders/{uv_o}/reworks', {'cause': 'impressao', 'metres': '0'}, expected=422)
admin.call(f'/operator/orders/{uv_o}/reworks', {'cause': 'impressao', 'metres': '1'}, expected=403)
signed_in(emails['vendedor'], 'outra-senha-de-teste').call(f'/operator/orders/{uv_o}/reworks',
{'cause': 'impressao', 'metres': '1'}, expected=403)
redo = coord.call(f'/operator/orders/{uv_o}/reworks', {'cause': 'impressao', 'metres': '0.5', 'note': 'Falhou'})
# Who printed it: the operator who sent it to Revisão, for their pay.
assert redo['printed_by'] == emails['operador'] and redo['authorized'] is None, redo
shown = next(o for o in admin.call('/operator/board')['orders'] if o['id'] == str(uv_o))['reworks']
# Names where the account exists; the operator's was deleted above, so their e-mail.
assert [(r['cause'], r['opened_name'], r['printed_name']) for r in shown] == [
('impressao', 'Mayana', emails['operador'])], shown
# Undecided, it does not count; it waits in Números.
waiting = figures()
assert cause(waiting, 'impressao') == cause(before, 'impressao')
assert redo['id'] in [p['id'] for p in waiting['pending']]
coord.call(f"/operator/reworks/{redo['id']}/decision", {'authorized': True}, expected=403)
admin.call(f"/operator/reworks/{redo['id']}/decision", {'authorized': False}, expected=422)
admin.call(f"/operator/reworks/{redo['id']}/decision", {'authorized': True})
admin.call(f"/operator/reworks/{redo['id']}/decision", {'authorized': True}, expected=409)
after = figures()
assert cause(after, 'impressao') == cause(before, 'impressao') + 0.5
assert after['house']['metres'] == before['house']['metres'] + 0.5 and after['house']['goal_percent'] == 1.6
# The customer's approved bad art counts apart, outside the house (D-04).
art = coord.call(f'/operator/orders/{uv_o}/reworks', {'cause': 'arte_cliente', 'metres': '2'})
admin.call(f"/operator/reworks/{art['id']}/decision", {'authorized': True})
last = figures()
assert cause(last, 'arte_cliente') == cause(after, 'arte_cliente') + 2
assert last['house']['metres'] == after['house']['metres']
# Declined, with its reason; and nobody decides a rework they opened.
wrong = coord.call(f'/operator/orders/{uv_o}/reworks', {'cause': 'pedido', 'metres': '1'})
declined = admin.call(f"/operator/reworks/{wrong['id']}/decision", {'authorized': False, 'reason': 'Não houve reimpressão'})
assert declined['authorized'] is False and declined['decline_reason'] == 'Não houve reimpressão'
assert cause(figures(), 'pedido') == cause(last, 'pedido')
own = su.call(f'/operator/orders/{uv_o}/reworks', {'cause': 'pedido', 'metres': '1'}, operator=True)
su.call(f"/operator/reworks/{own['id']}/decision", {'authorized': True}, operator=True, expected=409)
print('PASS: profiles limit actions, admins manage users but not the superadmin or themselves, '
'machines take orders by load and limit, keep a choice, and limit what their operators see')
finally: