fix: customer credit reaches Tiny as CREDITO PRE-PAGO, with its own marcador beside SITE DTF (#42)
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 7m45s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m25s
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 7m45s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m25s
Marcus, 2026-11-18: "Pago fora do site › Crédito do cliente" maps to the forma de recebimento CREDITO PRE-PAGO (987762591), and the order also gets the marcador CREDITO PRE-PAGO. CORREÇÃO DTF, refused by Tiny for #42, is for correction orders only. A retry adds only the marcadores the order is missing. The outbox computes the forma when it delivers, so #42's queued sale goes through on its next retry after the deploy. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
app/tiny.py
37
app/tiny.py
@@ -137,13 +137,14 @@ PICKUP_EXACT = 'retirar pessoalmente'
|
||||
# Dropstar's own ids, read from its store orders with app.tiny_probe exemplo
|
||||
# (2026-10-19). The app may not list formas de recebimento, so these are not
|
||||
# looked up: Pix and credit card, as the store's orders are paid, and the
|
||||
# DropStar carrier its pickup orders name. Dinheiro and, for the customer's
|
||||
# credit, Dropstar's own "CORREÇÃO DTF" were sent by Marcus on 2026-10-27, for
|
||||
# the orders the team registers as paid outside the site (D-35). "Boleto" is
|
||||
# DropStar carrier its pickup orders name. Dinheiro was sent by Marcus on
|
||||
# 2026-10-27, for the orders the team registers as paid outside the site
|
||||
# (D-35). The customer's credit is "CREDITO PRE-PAGO" (Marcus, 2026-11-18);
|
||||
# "CORREÇÃO DTF", used for it before, is for correction orders only. "Boleto" is
|
||||
# for a montador Venda order (front 7a.3); no id is known yet, and while
|
||||
# TINY_RECEIPT_BOLETO is empty the order goes without a forma de recebimento.
|
||||
_BOLETO = os.environ.get('TINY_RECEIPT_BOLETO', '').strip()
|
||||
RECEIPT_METHODS = {'pix': 919478952, 'card': 977460722, 'cash': 919478944, 'credit': 977493654,
|
||||
RECEIPT_METHODS = {'pix': 919478952, 'card': 977460722, 'cash': 919478944, 'credit': 987762591,
|
||||
**({'faturado': int(_BOLETO)} if _BOLETO.isdigit() else {})}
|
||||
PICKUP_CARRIER = 761565838
|
||||
# Dropstar's answers: the financial category "DTF SITE" (RECEITAS, id sent on
|
||||
@@ -157,6 +158,15 @@ CATEGORY = 986932924
|
||||
# the rules document (D-21) keeps the two channels apart in the financial.
|
||||
CATEGORIES = {'dropflow': 987032506}
|
||||
TAG = 'SITE DTF'
|
||||
# An order paid with the customer's credit also carries this marcador
|
||||
# (Marcus, 2026-11-18), beside SITE DTF.
|
||||
CREDIT_TAG = 'CREDITO PRE-PAGO'
|
||||
|
||||
|
||||
def order_tags(payload):
|
||||
"""The marcadores an order gets in Tiny."""
|
||||
paid = payload.get('payment') or {}
|
||||
return [TAG] + ([CREDIT_TAG] if paid.get('method') == 'credit' else [])
|
||||
# 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
|
||||
@@ -864,15 +874,17 @@ class TinyOrders:
|
||||
return detail
|
||||
return None
|
||||
|
||||
def tag(self, tiny_id, known=False):
|
||||
"""The SITE DTF marcador on the order, once. A retry that finds the
|
||||
order already created checks first, since POST adds another."""
|
||||
def tag(self, tiny_id, tags, known=False):
|
||||
"""The order's marcadores (order_tags), once each. A retry that finds
|
||||
the order already created checks first, since POST adds another."""
|
||||
missing = list(tags)
|
||||
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}])
|
||||
names = {str(m.get('descricao', '')).strip().upper() for m in have}
|
||||
missing = [tag for tag in tags if tag not in names]
|
||||
if missing:
|
||||
self.request('POST', f'/pedidos/{tiny_id}/marcadores', json=[{'descricao': tag} for tag in missing])
|
||||
|
||||
def set_situacao(self, tiny_id, situacao):
|
||||
self.request('PUT', f'/pedidos/{tiny_id}/situacao', json={'situacao': situacao})
|
||||
@@ -911,8 +923,9 @@ class TinyOrders:
|
||||
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
|
||||
tags = order_tags(payload)
|
||||
self.tag(tiny_id, tags, known=bool(existing))
|
||||
receipt['marcador'] = ', '.join(tags)
|
||||
if status_updates() and situacao == ABERTA:
|
||||
self.set_situacao(tiny_id, APROVADA)
|
||||
receipt['situacao'] = SITUACOES[APROVADA]
|
||||
|
||||
Reference in New Issue
Block a user