diff --git a/app/api/operator/quotes.py b/app/api/operator/quotes.py index 6e5e2b5..ecd985b 100644 --- a/app/api/operator/quotes.py +++ b/app/api/operator/quotes.py @@ -136,6 +136,11 @@ def register_order(uid: UUID, body: PaidOutside, user=Depends(can('enter'))): 'status': 'paid', 'total_cents': quote['approved']['total_cents'], 'operator': user} order, created = payments.create_order(c, quote, receipt, body.origin) if not created: + # A test order holds the quote too (orders.quote_id is unique): say so, + # and how to free it (Sentry DTF-WEB-D). + if payments.is_test(order): + raise HTTPException(409, f"Esta cotação já virou o pedido de teste #{order['number']}. " + 'Exclua o pedido de teste para registrar o pagamento.') 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 diff --git a/tests/payment_test.py b/tests/payment_test.py index ebbe3ea..a57e6a4 100644 --- a/tests/payment_test.py +++ b/tests/payment_test.py @@ -151,6 +151,10 @@ def run(): order = tester.call('/operator/quotes/' + test_quote + '/test-order', {}, operator=True) assert order['payment']['provider'] == 'teste' and order['state'] == 'rec', order assert tester.call('/operator/quotes/' + test_quote + '/test-order', {}, operator=True)['id'] == order['id'] + # The quote is that test order's now: registering it names the test order (Sentry DTF-WEB-D). + refused = tester.call('/operator/quotes/' + test_quote + '/register', {'origin': 'atendimento', 'method': 'cash'}, + operator=True, expected=409) + assert 'pedido de teste #' + str(order['number']) in refused['detail'], refused version = order['version'] # Arte conferida, the print queue, takes the order once its final is approved. from tests.smoke_test import final_png_bytes diff --git a/web/kanban-quotes.js b/web/kanban-quotes.js index b9b0499..832fa4a 100644 --- a/web/kanban-quotes.js +++ b/web/kanban-quotes.js @@ -196,7 +196,9 @@ function review(quote){ const test=button('Criar pedido de teste',async()=>{ if(!await ask('Criar um pedido de teste?','Ele entra em Arte recebida sem cobrar nada e não vai para o Tiny.','Criar pedido de teste'))return; const order=await api('/quotes/'+quote.id+'/test-order',{}); - say('Pedido de teste #'+order.number+' criado em Arte recebida.');await load(); + // The quote is now that test order's: it leaves the list, and its + // panel closes so nobody registers it again (Sentry DTF-WEB-D). + currentQuote=null;say('Pedido de teste #'+order.number+' criado em Arte recebida.');await load(); },'btn'); foot.append(test); if(chat)foot.append(chat);