feat: Site orders reach Tiny in the DUPLICADO DROP category, tagged KANBANDTF
Some checks failed
Build and deploy / Validate source (push) Successful in 1m29s
Build and deploy / Integration suite on a real stack (push) Successful in 5m8s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Failing after 1m34s
Some checks failed
Build and deploy / Validate source (push) Successful in 1m29s
Build and deploy / Integration suite on a real stack (push) Successful in 5m8s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Failing after 1m34s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
27
app/tiny.py
27
app/tiny.py
@@ -100,6 +100,12 @@ PICKUP_EXACT = 'retirar pessoalmente'
|
||||
# DropStar carrier its pickup orders name.
|
||||
RECEIPT_METHODS = {'pix': 919478952, 'card': 977460722}
|
||||
PICKUP_CARRIER = 761565838
|
||||
# Dropstar's answers (2026-10-21): the store's financial category "DUPLICADO
|
||||
# DROP" (it goes in pagamento.categoria), no seller (the team links one in
|
||||
# Tiny), and the marcador KANBANDTF, added after the order is created: POST
|
||||
# /pedidos does not take marcadores.
|
||||
CATEGORY = 965775137
|
||||
TAG = 'KANBANDTF'
|
||||
# Freight is the sender's (CIF), as on the store's orders.
|
||||
FREIGHT_PAID_BY = 'R'
|
||||
# The forma de envio each delivery service uses, by name; a Correios service
|
||||
@@ -460,12 +466,13 @@ def order_payload(payload, contact_id, today=None, product_id=None, shipping=Non
|
||||
if days is not None:
|
||||
pedido['dataPrevista'] = business_days_after(day, int(days)).isoformat()
|
||||
# Paid at once, in full, as the store's orders: one parcel on the day.
|
||||
pedido['pagamento'] = {'categoria': {'id': CATEGORY}}
|
||||
received = RECEIPT_METHODS.get((payload.get('payment') or {}).get('method'))
|
||||
if received:
|
||||
total = money(order['total_cents'])
|
||||
pedido['pagamento'] = {'formaRecebimento': {'id': received},
|
||||
'parcelas': [{'dias': 0, 'data': day.isoformat(), 'valor': total,
|
||||
'formaRecebimento': {'id': received}}]}
|
||||
pedido['pagamento'].update({'formaRecebimento': {'id': received},
|
||||
'parcelas': [{'dias': 0, 'data': day.isoformat(), 'valor': total,
|
||||
'formaRecebimento': {'id': received}}]})
|
||||
destination = order.get('destination')
|
||||
if destination:
|
||||
pedido['enderecoEntrega'] = {**address(destination), 'enderecoNro': destination['number'],
|
||||
@@ -660,6 +667,16 @@ class TinyOrders:
|
||||
return detail
|
||||
return None
|
||||
|
||||
def tag(self, tiny_id, known=False):
|
||||
"""The KANBANDTF marcador on the order, once. A retry that finds the
|
||||
order already created checks first, since POST adds another."""
|
||||
if known:
|
||||
have = self.request('GET', f'/pedidos/{tiny_id}/marcadores')
|
||||
have = have if isinstance(have, list) else have.get('itens') or []
|
||||
if any(str(m.get('descricao', '')).strip().upper() == TAG for m in have):
|
||||
return
|
||||
self.request('POST', f'/pedidos/{tiny_id}/marcadores', json=[{'descricao': TAG}])
|
||||
|
||||
def set_situacao(self, tiny_id, situacao):
|
||||
self.request('PUT', f'/pedidos/{tiny_id}/situacao', json={'situacao': situacao})
|
||||
|
||||
@@ -695,6 +712,10 @@ class TinyOrders:
|
||||
receipt = {'provider': 'tiny', 'event_key': event_key, 'status': 'created',
|
||||
'tiny_id': str(created.get('id')), 'tiny_number': str(created.get('numeroPedido'))}
|
||||
tiny_id, situacao = created.get('id'), ABERTA
|
||||
# Tagged before it is approved, so a failure here is retried while the order is still open.
|
||||
if situacao == ABERTA:
|
||||
self.tag(tiny_id, known=bool(existing))
|
||||
receipt['marcador'] = TAG
|
||||
if status_updates() and situacao == ABERTA:
|
||||
self.set_situacao(tiny_id, APROVADA)
|
||||
receipt['situacao'] = SITUACOES[APROVADA]
|
||||
|
||||
Reference in New Issue
Block a user