feat: a Tiny order can be the client's own SKUs per length, 1 metro plus the rest
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 2m31s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 59s

Dropstar's catalogue sells film as SKUs per length, and an order is a sum of
them: 1,30 m is one "1 metro" (DTFIMP.TX.100CM) and one "30 cm"
(DTFIMP.TX.0030CM). The adapter sent one product with the metres as the
quantity. TINY_SKU_<MODE> names a mode's SKU prefix; the order then carries
N times the metre SKU and one 10 cm SKU for the rest, at the price the
customer paid, the last line taking what is left of the item so the order
adds up to the cent. Each code is looked up once by its exact SKU among the
active products. "Testar conexão" and tiny_probe conferir check all ten, and
tiny_probe pedido takes --metros to show a split test order.

Modes without the setting keep their product id: UV and artes avulsas stay
that way until their SKUs are confirmed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-05 10:46:07 -03:00
parent a5c1ca53c0
commit e81b2b1681
7 changed files with 197 additions and 14 deletions

View File

@@ -4,8 +4,8 @@ Tiny has no sandbox, so this is how the adapter is proven on the real account.
python -m app.tiny_probe produtos [termo] list active products (read-only)
python -m app.tiny_probe formas-envio [termo] list formas de envio, to find pickup (read-only)
python -m app.tiny_probe conferir connection, the four product ids and pickup (read-only)
python -m app.tiny_probe pedido --cnpj ... --email ... --celular ... [--modo file]
python -m app.tiny_probe conferir connection, the products or SKUs and pickup (read-only)
python -m app.tiny_probe pedido --cnpj ... --email ... --celular ... [--modo file] [--metros 1.3]
show the test order; --confirmar creates it
The test order goes through TinyOrders.deliver, exactly as the worker sends a
@@ -20,6 +20,7 @@ import json
import sys
import time
from datetime import datetime
from decimal import Decimal, InvalidOperation
from .core.pricing import TIERS
from .core.secrets import load as load_secret_files
@@ -29,14 +30,16 @@ FIND_ATTEMPTS = 4
FIND_WAIT_SECONDS = 5
def test_order(cnpj, email, celular, mode, now=None):
def test_order(cnpj, email, celular, mode, now=None, metres='1'):
number = 'TESTE-' + (now or datetime.now(tiny.BRASILIA)).strftime('%Y%m%d%H%M')
unit = TIERS[mode][0][1]
total = int(Decimal(metres) * unit)
return {'order_id': 'teste-integracao', 'number': number, 'event': 'payment_approved',
'order': {'customer': {'cnpj': cnpj, 'mail': email, 'zap': celular},
'items': [{'mode': mode, 'grade': 100, 'billed_metres': '1', 'unit_cents': unit}],
'items': [{'mode': mode, 'grade': 100, 'billed_metres': metres, 'unit_cents': unit,
'total_cents': total}],
'freight': {'service': 'pickup', 'total_cents': 0},
'destination': None, 'total_cents': unit}}
'destination': None, 'total_cents': total}}
def produtos(orders, termo, out):
@@ -64,6 +67,13 @@ def formas_envio(orders, termo, out):
def conferir(orders, out):
ok = True
for mode, setting in tiny.PRODUCT_SETTINGS.items():
prefix = tiny.sku_prefix(mode)
if prefix:
result = tiny.configured_skus(orders, mode)
ok &= result == 'ok'
out(f'{tiny.SKU_SETTINGS[mode]} ({tiny.PRODUCTS[mode]}): {result} '
f'({prefix}.100CM e {prefix}.0010CM a {prefix}.0090CM)')
continue
product, result = tiny.configured_product(orders, mode)
ok &= result == 'ok'
described = f"{product.get('sku') or '-'} · {product.get('descricao')}" if product else ''
@@ -87,7 +97,8 @@ def pedido(orders, payload, confirm, out, wait=time.sleep):
out(f"Contato {cnpj}: " + (f"já existe no Tiny (id {known[0]['id']})" if known
else 'não existe; será criado com o e-mail como nome'))
out('Pedido que será enviado:')
out(json.dumps(tiny.order_payload(payload, known[0]['id'] if known else 0), ensure_ascii=False, indent=2))
out(json.dumps(tiny.order_payload(payload, known[0]['id'] if known else 0, product_id=orders.product_id),
ensure_ascii=False, indent=2))
if not confirm:
out('Nada foi criado. Repita com --confirmar para criar este pedido no Tiny.')
return None
@@ -124,6 +135,7 @@ def main(argv=None, orders=None, out=print):
order.add_argument('--email', required=True)
order.add_argument('--celular', required=True)
order.add_argument('--modo', choices=sorted(tiny.PRODUCT_SETTINGS), default='file')
order.add_argument('--metros', default='1', help='metragem cobrada, em passos de 10 cm (ex.: 1.3)')
order.add_argument('--confirmar', action='store_true')
args = parser.parse_args(argv)
if orders is None:
@@ -142,7 +154,14 @@ def main(argv=None, orders=None, out=print):
if len(cnpj) != 14:
out('Informe um CNPJ com 14 dígitos.')
return 2
payload = test_order(cnpj, args.email, args.celular, args.modo)
try:
metres = Decimal(args.metros.replace(',', '.'))
except InvalidOperation:
metres = Decimal(0)
if metres < 1 or (metres * 10) % 1:
out('Informe a metragem a partir de 1 m, em passos de 10 cm (ex.: 1.3).')
return 2
payload = test_order(cnpj, args.email, args.celular, args.modo, metres=str(metres))
return 0 if pedido(orders, payload, args.confirmar, out) is not False else 1
except tiny.TinyError as exc:
out(f'Tiny: {exc}')