feat: drop a card on the machine it prints on; Pagamentos says who paid
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
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 57s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
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 57s
- Imprimindo: every active machine has its lane, and a card dragged from the queue onto a lane goes to that machine (if it prints the product and has a place), instead of the one it came with. The operator's pull still goes to the machine they are on (item 12). - Pagamentos: each payment shows who tried to pay and what they were buying (the quote's customer and items, and its order if there is one); a click opens the customer's name, e-mail, CPF/CNPJ, WhatsApp and delivery, the quote, and Mercado Pago's id and status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -283,7 +283,31 @@ def payment_events(state: Literal['open','resolved','all'] = 'open',
|
||||
ORDER BY received_at DESC,id DESC LIMIT %s OFFSET %s''', (limit, offset)).fetchall()
|
||||
total = c.execute('''SELECT count(*) AS n FROM dtf_local.payment_events
|
||||
WHERE (outcome LIKE 'refused%' OR outcome LIKE 'attention%') ''' + where).fetchone()['n']
|
||||
return {'issues': rows, 'total': total}
|
||||
for row in rows:
|
||||
row.update(payment_context(c, row))
|
||||
return {'issues': rows, 'total': total, 'thumbnails': thumbnails(c, [r['quote'] for r in rows if r.get('quote')])}
|
||||
|
||||
|
||||
def payment_context(c, row):
|
||||
"""Who tried to pay and for what: the quote the payment points to (its
|
||||
customer, items and total), its order if there is one, the method of the
|
||||
last attempt and Mercado Pago's own words about the payment."""
|
||||
payload = c.execute('SELECT payload FROM dtf_local.payment_events WHERE id=%s', (row['id'],)).fetchone()['payload'] or {}
|
||||
out = {'payment_id': payload.get('payment_id'), 'status_detail': payload.get('status_detail'), 'quote': None, 'order': None, 'method': None}
|
||||
try:
|
||||
quote_id = UUID(str(row.get('reference') or ''))
|
||||
except ValueError:
|
||||
return out
|
||||
quote = c.execute('SELECT id,draft,approved,created_at,approved_at FROM dtf_local.quotes WHERE id=%s', (quote_id,)).fetchone()
|
||||
if not quote:
|
||||
return out
|
||||
out['quote'] = {'id': quote['id'], 'draft': quote['draft'], 'created_at': quote['created_at'], 'approved_at': quote['approved_at'],
|
||||
'total_cents': (quote['approved'] or {}).get('total_cents')}
|
||||
out['order'] = c.execute('SELECT id,number,state,cancelled_at FROM dtf_local.orders WHERE quote_id=%s', (quote_id,)).fetchone()
|
||||
attempt = c.execute('''SELECT method,status FROM dtf_local.payment_intents WHERE quote_id=%s
|
||||
ORDER BY created_at DESC LIMIT 1''', (quote_id,)).fetchone()
|
||||
out['method'] = attempt['method'] if attempt else None
|
||||
return out
|
||||
|
||||
|
||||
@router.get('/api/operator/events')
|
||||
@@ -870,7 +894,22 @@ def move(uid: UUID, body: Move, request: Request, user=Depends(operator)):
|
||||
raise HTTPException(409, 'Escolha a máquina em que você está.')
|
||||
if not pulling and str(row['machine_id'] or '') != session_machine['id']:
|
||||
raise HTTPException(403, 'Este pedido é de outra máquina: só quem está nela move o card.')
|
||||
if pulling and session_machine and (account['role'] == 'operador' or not row['machine_chosen']):
|
||||
# Dropped on a machine's lane in Imprimindo: that machine, when it
|
||||
# prints the product. The operator's pull stays their machine's.
|
||||
if pulling and body.machine_id:
|
||||
if account['role'] == 'operador':
|
||||
if str(body.machine_id) != session_machine['id']:
|
||||
raise HTTPException(409, f"Você está na {session_machine['name']}: o que você puxa vai para ela.")
|
||||
else:
|
||||
target = c.execute('SELECT name, products, active FROM dtf_local.machines WHERE id=%s',
|
||||
(body.machine_id,)).fetchone()
|
||||
if not target or not target['active']:
|
||||
raise HTTPException(409, 'Essa máquina não existe mais ou está desativada.')
|
||||
if machines.product_family(row) not in target['products']:
|
||||
raise HTTPException(409, f"A {target['name']} não imprime este produto.")
|
||||
row['machine_id'] = body.machine_id
|
||||
c.execute('UPDATE dtf_local.orders SET machine_id=%s, machine_chosen=true WHERE id=%s', (body.machine_id, uid))
|
||||
if pulling and session_machine and not body.machine_id and (account['role'] == 'operador' or not row['machine_chosen']):
|
||||
prints = c.execute('SELECT products FROM dtf_local.machines WHERE id=%s', (session_machine['id'],)).fetchone()
|
||||
if machines.product_family(row) in (prints or {}).get('products', []):
|
||||
row['machine_id'] = session_machine['id']
|
||||
|
||||
@@ -264,6 +264,8 @@ class Move(StrictModel):
|
||||
state: Literal['rec','tra','imp','cor','rev','fin']
|
||||
version: int = Field(ge=0)
|
||||
reason: str = Field(default='', max_length=1000)
|
||||
# Pulled into Imprimindo onto a machine's lane: the machine it prints on.
|
||||
machine_id: UUID | None = None
|
||||
|
||||
class Resolution(StrictModel):
|
||||
note: str = Field(min_length=3, max_length=1000)
|
||||
|
||||
Reference in New Issue
Block a user