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

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:
Cauê Faleiros
2026-11-18 12:24:21 -03:00
parent a52856f3f6
commit b3ecba590b
2 changed files with 41 additions and 15 deletions

View File

@@ -137,13 +137,14 @@ PICKUP_EXACT = 'retirar pessoalmente'
# Dropstar's own ids, read from its store orders with app.tiny_probe exemplo # 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 # (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 # 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 # DropStar carrier its pickup orders name. Dinheiro was sent by Marcus on
# credit, Dropstar's own "CORREÇÃO DTF" were sent by Marcus on 2026-10-27, for # 2026-10-27, for the orders the team registers as paid outside the site
# the orders the team registers as paid outside the site (D-35). "Boleto" is # (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 # 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. # TINY_RECEIPT_BOLETO is empty the order goes without a forma de recebimento.
_BOLETO = os.environ.get('TINY_RECEIPT_BOLETO', '').strip() _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 {})} **({'faturado': int(_BOLETO)} if _BOLETO.isdigit() else {})}
PICKUP_CARRIER = 761565838 PICKUP_CARRIER = 761565838
# Dropstar's answers: the financial category "DTF SITE" (RECEITAS, id sent on # 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. # the rules document (D-21) keeps the two channels apart in the financial.
CATEGORIES = {'dropflow': 987032506} CATEGORIES = {'dropflow': 987032506}
TAG = 'SITE DTF' 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 is the sender's (CIF), as on the store's orders.
FREIGHT_PAID_BY = 'R' FREIGHT_PAID_BY = 'R'
# The forma de envio each delivery service uses, by name; a Correios service # The forma de envio each delivery service uses, by name; a Correios service
@@ -864,15 +874,17 @@ class TinyOrders:
return detail return detail
return None return None
def tag(self, tiny_id, known=False): def tag(self, tiny_id, tags, known=False):
"""The SITE DTF marcador on the order, once. A retry that finds the """The order's marcadores (order_tags), once each. A retry that finds
order already created checks first, since POST adds another.""" the order already created checks first, since POST adds another."""
missing = list(tags)
if known: if known:
have = self.request('GET', f'/pedidos/{tiny_id}/marcadores') have = self.request('GET', f'/pedidos/{tiny_id}/marcadores')
have = have if isinstance(have, list) else have.get('itens') or [] have = have if isinstance(have, list) else have.get('itens') or []
if any(str(m.get('descricao', '')).strip().upper() == TAG for m in have): names = {str(m.get('descricao', '')).strip().upper() for m in have}
return missing = [tag for tag in tags if tag not in names]
self.request('POST', f'/pedidos/{tiny_id}/marcadores', json=[{'descricao': TAG}]) if missing:
self.request('POST', f'/pedidos/{tiny_id}/marcadores', json=[{'descricao': tag} for tag in missing])
def set_situacao(self, tiny_id, situacao): def set_situacao(self, tiny_id, situacao):
self.request('PUT', f'/pedidos/{tiny_id}/situacao', json={'situacao': 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 tiny_id, situacao = created.get('id'), ABERTA
# Tagged before it is approved, so a failure here is retried while the order is still open. # Tagged before it is approved, so a failure here is retried while the order is still open.
if situacao == ABERTA: if situacao == ABERTA:
self.tag(tiny_id, known=bool(existing)) tags = order_tags(payload)
receipt['marcador'] = TAG self.tag(tiny_id, tags, known=bool(existing))
receipt['marcador'] = ', '.join(tags)
if status_updates() and situacao == ABERTA: if status_updates() and situacao == ABERTA:
self.set_situacao(tiny_id, APROVADA) self.set_situacao(tiny_id, APROVADA)
receipt['situacao'] = SITUACOES[APROVADA] receipt['situacao'] = SITUACOES[APROVADA]

View File

@@ -455,13 +455,14 @@ class TinyStatusTests(FakeTinyCase):
1, thursday, shipping=self.tiny.shipping) 1, thursday, shipping=self.tiny.shipping)
self.assertEqual(pix['pagamento']['formaRecebimento'], {'id': RECEIPT_METHODS['pix']}) self.assertEqual(pix['pagamento']['formaRecebimento'], {'id': RECEIPT_METHODS['pix']})
self.assertEqual(pix['pagamento']['categoria'], {'id': CATEGORY}) self.assertEqual(pix['pagamento']['categoria'], {'id': CATEGORY})
# Dinheiro and the customer's credit (CORREÇÃO DTF), Marcus's ids of 2026-10-27. # Dinheiro (Marcus, 2026-10-27) and the customer's credit, CREDITO
self.assertEqual((RECEIPT_METHODS['cash'], RECEIPT_METHODS['credit']), (919478944, 977493654)) # PRE-PAGO (Marcus, 2026-11-18; no longer CORREÇÃO DTF).
self.assertEqual((RECEIPT_METHODS['cash'], RECEIPT_METHODS['credit']), (919478944, 987762591))
# A Dropflow order goes in DTF DROPFLOW, not DTF SITE (D-21). # A Dropflow order goes in DTF DROPFLOW, not DTF SITE (D-21).
batch = order_payload({**PAID, 'origin': 'dropflow', 'payment': {'method': 'credit', 'outside': True}}, batch = order_payload({**PAID, 'origin': 'dropflow', 'payment': {'method': 'credit', 'outside': True}},
1, thursday, shipping=self.tiny.shipping) 1, thursday, shipping=self.tiny.shipping)
self.assertEqual(batch['pagamento']['categoria'], {'id': 987032506}) self.assertEqual(batch['pagamento']['categoria'], {'id': 987032506})
self.assertEqual(batch['pagamento']['formaRecebimento'], {'id': 977493654}) self.assertEqual(batch['pagamento']['formaRecebimento'], {'id': 987762591})
self.assertTrue(batch['observacoesInternas'].startswith('Dropflow DTF · pago fora do site (crédito do cliente) · ')) self.assertTrue(batch['observacoesInternas'].startswith('Dropflow DTF · pago fora do site (crédito do cliente) · '))
def test_the_order_is_tagged_kanbandtf_once(self): def test_the_order_is_tagged_kanbandtf_once(self):
@@ -474,6 +475,18 @@ class TinyStatusTests(FakeTinyCase):
self.assertEqual(len(self.orders), 1) self.assertEqual(len(self.orders), 1)
self.assertEqual(self.tags[tiny_id], [{'descricao': 'SITE DTF'}]) self.assertEqual(self.tags[tiny_id], [{'descricao': 'SITE DTF'}])
def test_customer_credit_also_carries_the_credito_pre_pago_marcador(self):
credit = {**PAID, 'payment': {'method': 'credit', 'outside': True}}
first = self.tiny.deliver('k1', credit)
self.assertEqual(first['marcador'], 'SITE DTF, CREDITO PRE-PAGO')
tiny_id = self.orders[0]['id']
self.assertEqual(self.orders[0]['pagamento']['formaRecebimento'], {'id': 987762591})
self.assertEqual(self.tags[tiny_id], [{'descricao': 'SITE DTF'}, {'descricao': 'CREDITO PRE-PAGO'}])
# A retry adds only what is missing.
self.tags[tiny_id] = [{'descricao': 'SITE DTF'}]
self.tiny.deliver('k1', credit)
self.assertEqual(self.tags[tiny_id], [{'descricao': 'SITE DTF'}, {'descricao': 'CREDITO PRE-PAGO'}])
def test_a_failed_tag_is_retried_without_a_second_order(self): def test_a_failed_tag_is_retried_without_a_second_order(self):
self.refuse_tag = 1 self.refuse_tag = 1
with self.assertRaises(TinyError): with self.assertRaises(TinyError):