feat: customers show by their company's name, taken from the CNPJ registry
The Site asks for e-mail, CNPJ and WhatsApp only, so the Kanban showed an e-mail where a name belongs and a new Tiny contact was named after it. The worker now looks up each customer's CNPJ in the public registry (BrasilAPI, no key) a few at a time, never while a customer waits, and keeps the razão social and trade name in dtf_local.cnpj_names; a failed lookup is retried a day later. Cards, the order panel, quotes and the search results show the trade name (else the razão social) above the e-mail, the search finds orders and quotes by either name, and a new Tiny contact gets the razão social as its name and the trade name as fantasia. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,10 +18,12 @@ adapters = {'tiny': FakeTiny(), 'whatsapp': FakeWhatsApp()}
|
||||
# Not yet confirmed against the client's account; see app/tiny.py.
|
||||
if os.environ.get('TINY_ADAPTER') == 'tiny':
|
||||
from .tiny import TinyOrders
|
||||
adapters['tiny'] = TinyOrders()
|
||||
from .cnpj import company
|
||||
adapters['tiny'] = TinyOrders(names=company)
|
||||
last_tick = 0.0
|
||||
last_cleanup = 0.0
|
||||
last_reconcile = 0.0
|
||||
last_names = 0.0
|
||||
last_tiny_keepalive = 0.0
|
||||
storage = LocalS3Storage()
|
||||
scan_thread = None
|
||||
@@ -87,6 +89,15 @@ def reconcile_payments():
|
||||
from .runtime import payment
|
||||
payments.reconcile(connect, payment)
|
||||
|
||||
def resolve_names():
|
||||
"""Every minute: the company names of a few new customers' CNPJs."""
|
||||
global last_names
|
||||
if time.monotonic()-last_names < 60:
|
||||
return
|
||||
last_names = time.monotonic()
|
||||
from . import cnpj
|
||||
cnpj.resolve(connect)
|
||||
|
||||
def loop():
|
||||
global last_cleanup
|
||||
while True:
|
||||
@@ -97,6 +108,7 @@ def loop():
|
||||
last_cleanup = time.monotonic()
|
||||
tiny_keepalive()
|
||||
reconcile_payments()
|
||||
resolve_names()
|
||||
except Exception:
|
||||
logging.exception('Local worker tick failed')
|
||||
time.sleep(1)
|
||||
|
||||
Reference in New Issue
Block a user