feat: montador Interno and Venda, Tiny customers, brand per stamp (front 7a.3, Marcus 10/11)

Interno: the Expedição assembles the marketplace's own sales on the fixed
internal customer Gestão fills in once; no Tiny order, no paid e-mail,
marked interno, it stays in house. Venda: a Vendedor or Gestão picks the
customer from the Tiny base and the order goes to Tiny like an approved
quote, faturado (Boleto from TINY_RECEIPT_BOLETO when set), pickup or
'junto com o pedido de roupa nº X'. Números counts both at table price,
apart from cash (and the average ticket over cash orders only). Each stamp
can carry a brand and a public flag for the future catalogue.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-11 11:01:44 -03:00
parent e6197d6e40
commit b5a51137fb
15 changed files with 710 additions and 97 deletions

View File

@@ -103,8 +103,19 @@ OUTSIDE_NOTES = {'pix': 'Pix', 'card': 'cartão', 'cash': 'dinheiro', 'credit':
def internal_note(payload):
paid = payload.get('payment') or {}
how = f"pago fora do site ({OUTSIDE_NOTES.get(paid.get('method'), paid.get('method'))})" if paid.get('outside') else 'pago'
return f"{ORIGIN_NOTES.get(payload.get('origin') or 'site')} · {how} · {payload['order_id']}"
method = paid.get('method')
if method == 'faturado':
# A montador Venda order is invoiced (front 7a.3): its forma de
# recebimento is "Boleto" when the client's id is configured.
boleto = os.environ.get('TINY_RECEIPT_BOLETO', '').strip()
how = 'faturado (Boleto)' if boleto.isdigit() else 'faturado: forma de recebimento a definir'
else:
how = f"pago fora do site ({OUTSIDE_NOTES.get(method, method)})" if paid.get('outside') else 'pago'
note = f"{ORIGIN_NOTES.get(payload.get('origin') or 'site')} · {how} · {payload['order_id']}"
with_order = (payload.get('order') or {}).get('with_order')
if with_order:
note += f' · junto com o pedido de roupa nº {with_order}'
return note
STATUS_UPDATES_SETTING = 'TINY_STATUS_UPDATES'
@@ -119,8 +130,12 @@ PICKUP_EXACT = 'retirar pessoalmente'
# 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).
RECEIPT_METHODS = {'pix': 919478952, 'card': 977460722, 'cash': 919478944, 'credit': 977493654}
# the orders the team registers as paid outside the site (D-35). "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,
**({'faturado': int(_BOLETO)} if _BOLETO.isdigit() else {})}
PICKUP_CARRIER = 761565838
# Dropstar's answers: the financial category "DTF SITE" (RECEITAS, id sent on
# 2026-10-26; it goes in pagamento.categoria, and replaced the store's
@@ -438,6 +453,30 @@ def search_forms(document):
return list(dict.fromkeys((punctuated(d), d)))
def search_contacts(orders, query, limit=10):
"""Up to `limit` contacts matching what was typed (the montador's typeahead,
front 7a.3): by CPF/CNPJ when it is only digits and punctuation, else by
name. Tiny's own search does the matching."""
text = str(query or '').strip()
digits = ''.join(ch for ch in text if ch.isdigit())
found = []
if digits and not any(ch.isalpha() for ch in text):
for form in search_forms(digits):
found += orders.request('GET', '/contatos', params={'cpfCnpj': form, 'limit': limit}).get('itens') or []
else:
found = orders.request('GET', '/contatos', params={'nome': text, 'limit': limit}).get('itens') or []
contacts, seen = [], set()
for entry in found:
if entry.get('id') in seen:
continue
seen.add(entry.get('id'))
contacts.append({'id': entry.get('id'), 'name': entry.get('nome') or '',
'document': entry.get('cpfCnpj') or '',
'email': entry.get('email') or '',
'phone': entry.get('telefone') or entry.get('celular') or ''})
return contacts[:limit]
def contact_payload(order, company=None):
"""A new contact, named after the company's razão social when the
registry gave it (app/cnpj.py), else the customer's name, else the