From fc9e6d268159b4446c6fac86d1120fdec6ba6472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Tue, 1 Dec 2026 10:58:31 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20an=20order=20paid=20on=20the=20Site=20s?= =?UTF-8?q?ays=20how:=20"pago=20com=20Pix"=20or=20"pago=20com=20cart=C3=A3?= =?UTF-8?q?o"=20on=20its=20paid=20line?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The board carries paid_with, the method of the quote's approved payment attempt (the one Tiny is told about). Until now a paid Site order only said "pago em", so a Tiny refusal (DTF-API-C, #196) could not be traced to Pix or card from the Kanban. Co-Authored-By: Claude Opus 5.5 --- app/api/operator/board.py | 6 ++++++ tests/payment_test.py | 15 +++++++++++++++ web/kanban-order.js | 3 ++- web/kanban-quotes.js | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/api/operator/board.py b/app/api/operator/board.py index 654dbe0..d11a594 100644 --- a/app/api/operator/board.py +++ b/app/api/operator/board.py @@ -235,6 +235,11 @@ def with_print_files(c, orders): WHERE parent_id=ANY(%s) AND cancelled_at IS NULL ORDER BY parent_id, created_at DESC''', (ids,)).fetchall()} parents = {r['id']: r for r in c.execute('SELECT id,number,state FROM dtf_local.orders WHERE id=ANY(%s)', ([o['parent_id'] for o in orders if o.get('parent_id')],)).fetchall()} + # How each Site order was paid, Pix or card: its quote's approved attempt, + # the one Tiny is told about too (app/payments.py). + paid_with = {r['quote_id']: r['method'] for r in c.execute('''SELECT DISTINCT ON (quote_id) quote_id,method + FROM dtf_local.payment_intents WHERE quote_id=ANY(%s) AND status='approved' ORDER BY quote_id,created_at DESC''', + ([o['quote_id'] for o in orders if o.get('quote_id')],)).fetchall()} # Every order's review photos and videos, in one query like the print files. review_rows = reviews.by_order(c, ids) # The proof card's go on its order too: an answered card leaves the board, @@ -244,6 +249,7 @@ def with_print_files(c, orders): for order in orders: order['hot'] = hot.get(order['id']) order['hot_parts'] = hot_parts.get(order['id'], []) + order['paid_with'] = paid_with.get(order.get('quote_id')) order['reviews'] = review_rows.get(str(order['id']), []) child = children.get(order['id']) # Its machine: an order prints where its approved proof did (Dropstar, 2026-11-05). diff --git a/tests/payment_test.py b/tests/payment_test.py index 8dc5899..a02b9a2 100644 --- a/tests/payment_test.py +++ b/tests/payment_test.py @@ -142,6 +142,21 @@ def run(): assert [e['provider'] for e in paid] == ['tiny'], paid print('PASS: exactly one Tiny notification for the order') + # The order's paid line says how it was paid: nothing while no attempt is + # approved, then the approved one (the card attempt above). + def paid_with(): + orders = board.call('/operator/board', operator=True)['orders'] + return next(o for o in orders if o['id'] == order['id'])['paid_with'] + assert paid_with() is None + with db.connect() as c: + c.execute("UPDATE dtf_local.payment_intents SET status='approved' WHERE quote_id=%s AND method='card'", (quote_id,)) + try: + assert paid_with() == 'card' + finally: + with db.connect() as c: + c.execute("UPDATE dtf_local.payment_intents SET status='pending' WHERE quote_id=%s AND method='card'", (quote_id,)) + print('PASS: the board says the order was paid with the approved attempt, card') + # A payment that was never reviewed, and one for something that is not a quote. deliver({'event_id': 'nonsense-' + uuid4().hex, 'reference': 'not-a-uuid', 'status': 'approved', 'amount_cents': 100}) diff --git a/web/kanban-order.js b/web/kanban-order.js index 0de853f..f53d250 100644 --- a/web/kanban-order.js +++ b/web/kanban-order.js @@ -53,7 +53,8 @@ function renderPanel(order){ // A proof card is no sale (app/proof.py): it says whose proof it is. if(order.proof_parent)paid.append(node('b','Prova do pedido #'+order.proof_parent.number),', sem custo, criada em '+when(order.created_at)); else paid.append(node('b',money(s.total_cents)),isTest(order)?' sem pagamento, '+when(order.created_at): - paidOutside(order)?' pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado em '+when(order.created_at):' pago em '+when(order.created_at)); + paidOutside(order)?' pago fora do site ('+(PAID_OUTSIDE[order.payment.method]||order.payment.method)+'), registrado em '+when(order.created_at): + ' pago'+(PAID_WITH[order.paid_with]?' com '+PAID_WITH[order.paid_with]:'')+' em '+when(order.created_at)); const code=node('span',undefined,'chip'); code.append(node('span','DTF-'+order.number,'code'),copyButton(fileCode(order),'Copiar “'+fileCode(order)+'”, o começo do nome dos arquivos deste pedido')); const theirs=node('span','Código do cliente ','tip-l');theirs.append(node('span',orderCode(order.id),'code strong'));theirs.dataset.tip='O código que aparece para o cliente'; diff --git a/web/kanban-quotes.js b/web/kanban-quotes.js index 00eb2bc..916d944 100644 --- a/web/kanban-quotes.js +++ b/web/kanban-quotes.js @@ -238,6 +238,8 @@ function callout(d,title,text,tone=''){ // Faturado is not one of them: an invoiced sale goes through the montador's // Venda (front 7a.3), and the API refuses it here (Sentry DTF-WEB-E). const PAID_OUTSIDE={pix:'Pix',card:'Cartão',cash:'Dinheiro',credit:'Crédito do cliente'}; +// How a Site order was paid, on the order's paid line (the board's paid_with). +const PAID_WITH={pix:'Pix',card:'cartão'}; function registerDialog(quote){ const group=(name,label,options)=>{ const g=node('div',undefined,'fgroup2');g.setAttribute('role','radiogroup');g.setAttribute('aria-label',label);