feat: the team registers an order paid outside the site, choosing its origin and payment (Dropstar's rule D-35)
Some checks failed
Build and deploy / Integration suite on a real stack (push) Failing after 3m26s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Has been skipped
Build and deploy / Validate source (push) Successful in 6s

On an approved quote in Cotacoes, Administrador, Gestao and Vendedor pick
the origin (Site, Dropflow, Atendimento) and how it was paid (Pix, cartao,
dinheiro, credito do cliente), neither preselected, with an optional note.
The price is the quote's, the Site's table price. The order is marked paid
outside, counts in Numeros, and goes to Tiny like a Site order with the
payment named in its internal note; a Dropflow order stays out of Tiny,
status updates and cancelling included, until its revenue category exists.
Auto-refresh waits while a register form on screen is half filled in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-27 12:36:40 -03:00
parent 0319039328
commit c45e5f732b
12 changed files with 176 additions and 23 deletions

View File

@@ -422,12 +422,40 @@ def test_order(uid: UUID, user=Depends(can('manage'))):
raise HTTPException(404 if 'not found' in str(refusal) else 409, str(refusal))
receipt = {'provider': payments.TEST_PROVIDER, 'id': f'teste-{uid}', 'status': 'paid',
'total_cents': quote['approved']['total_cents'], 'operator': user}
order, created = payments.create_order(c, quote, receipt)
order, created = payments.create_order(c, quote, receipt, 'site')
if created:
audit('test_order_created', order=str(order['id']), operator=user)
return order
class PaidOutside(StrictModel):
# No defaults (D-35): whoever registers the order says where it came from
# and how it was paid.
origin: Literal['site', 'dropflow', 'atendimento']
method: Literal[payments.OUTSIDE_METHODS]
note: str = Field(default='', max_length=300)
@router.post('/api/operator/quotes/{uid}/register')
def register_order(uid: UUID, body: PaidOutside, user=Depends(can('enter'))):
"""The order for an approved quote paid outside the system (Dropstar's
rule D-35): the team builds the cart on the Site, as a customer would, and
registers it here with its origin and how it was paid. The price is the
quote's, the Site's table price."""
with db.connect() as c:
try:
quote = payments.approved_quote(c, uid)
except payments.PaymentRefused as refusal:
raise HTTPException(404 if 'not found' in str(refusal) else 409, str(refusal))
receipt = {'provider': payments.MANUAL_PROVIDER, 'method': body.method, 'note': body.note.strip(),
'status': 'paid', 'total_cents': quote['approved']['total_cents'], 'operator': user}
order, created = payments.create_order(c, quote, receipt, body.origin)
if not created:
raise HTTPException(409, f"Esta cotação já virou o pedido #{order['number']}.")
audit('manual_order_registered', order=str(order['id']), origin=body.origin, operator=user)
return order
@router.post('/api/operator/quotes/{uid}/discard')
def discard_quote(uid: UUID, user=Depends(can('manage'))):
"""An unpaid quote leaves the Kanban and can no longer be paid. Its files
@@ -513,7 +541,7 @@ def cancel_order(uid: UUID, body: Resolution, user=Depends(can('manage'))):
(user, body.note, uid)).fetchone()
if not row:
raise HTTPException(404, 'Pedido não encontrado ou já cancelado.')
if not payments.is_test(row):
if payments.in_tiny(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',
@@ -664,7 +692,7 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
# Entering the queue (Arte conferida) is Tiny's "Preparando envio";
# Finalizado its "Pronto para envio" (Dropstar's flow, 2026-10-23).
events = {'tra':'production_started','cor':'correction_needed','fin':'ready'}
if body.state in events and not back and not payments.is_test(row):
if body.state in events and not back and payments.in_tiny(row):
# "Production started" and "ready" reach the customer once per order,
# even if a mistaken move is undone and made again. Each correction
# is a new request, so it keeps one message per movement.