feat: the cart and the account ask for the customer's name
All checks were successful
Build and deploy / Validate source (push) Successful in 10s
Build and deploy / Integration suite on a real stack (push) Successful in 4m49s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m15s
All checks were successful
Build and deploy / Validate source (push) Successful in 10s
Build and deploy / Integration suite on a real stack (push) Successful in 4m49s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m15s
The Site asked only for CPF/CNPJ, WhatsApp and e-mail, so a person's Tiny contact was named after the recipient or the e-mail, and the WhatsApp notices the client's n8n sends from Tiny greeted "Olá, fulano@gmail.com". The cart's "Seus dados" and the signup now ask for a name, the account page can change it, and it names a CPF customer's Tiny contact (a CNPJ keeps the registry's razão social), the Kanban card and the team's alerts. Orders placed before have none, as the server still accepts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -256,12 +256,14 @@ def account_row(c, identity, lock=False):
|
||||
|
||||
@router.post('/api/account/profile')
|
||||
def update_profile(body: ProfileUpdate, identity=Depends(owner)):
|
||||
"""WhatsApp and the saved delivery address. The CPF or CNPJ is the account's and
|
||||
"""Name, WhatsApp and the saved delivery address. The CPF or CNPJ is the account's and
|
||||
does not change; the e-mail is the login and changes on its own route."""
|
||||
with db.connect() as c:
|
||||
row = account_row(c, identity, lock=True)
|
||||
profile = {**row['profile'], 'zap': body.zap,
|
||||
'address': body.address.model_dump() if body.address else None}
|
||||
if body.name is not None:
|
||||
profile['name'] = body.name
|
||||
c.execute('UPDATE dtf_local.accounts SET profile=%s WHERE id=%s', (Jsonb(profile), identity))
|
||||
audit('account_profile_updated', account=str(identity))
|
||||
return {'customer': profile}
|
||||
|
||||
@@ -21,12 +21,27 @@ def cnpj_ok(digits):
|
||||
and check_digit(digits[:12], [5,4,3,2,9,8,7,6,5,4,3,2]) == int(digits[12])
|
||||
and check_digit(digits[:13], [6,5,4,3,2,9,8,7,6,5,4,3,2]) == int(digits[13]))
|
||||
|
||||
def person_name(value):
|
||||
"""A name as typed, with its spaces tidied; at least two letters when given."""
|
||||
name = ' '.join(str(value or '').split())
|
||||
if name and sum(ch.isalpha() for ch in name) < 2:
|
||||
raise ValueError('Invalid name')
|
||||
return name
|
||||
|
||||
class Customer(StrictModel):
|
||||
# The customer's CPF or CNPJ, digits only. The key keeps the name it had
|
||||
# when only companies bought, as stored orders, quotes and accounts use it.
|
||||
cnpj: str
|
||||
zap: str
|
||||
mail: str = Field(max_length=254)
|
||||
# Who to greet: the Tiny contact and the WhatsApp notices use it. Empty in
|
||||
# orders placed before the Site asked for it.
|
||||
name: str = Field(default='', max_length=80)
|
||||
|
||||
@field_validator('name')
|
||||
@classmethod
|
||||
def name_valid(cls, value):
|
||||
return person_name(value)
|
||||
|
||||
@field_validator('cnpj')
|
||||
@classmethod
|
||||
@@ -243,9 +258,15 @@ class Register(StrictModel):
|
||||
password: str = Field(min_length=12, max_length=128)
|
||||
|
||||
class ProfileUpdate(StrictModel):
|
||||
"""What a customer may change about their account; the CNPJ is not among it."""
|
||||
"""What a customer may change about their account; the CPF/CNPJ is not among it."""
|
||||
zap: str
|
||||
address: Destination | None = None
|
||||
name: str | None = Field(default=None, max_length=80)
|
||||
|
||||
@field_validator('name')
|
||||
@classmethod
|
||||
def name_valid(cls, value):
|
||||
return None if value is None else person_name(value)
|
||||
|
||||
@field_validator('zap')
|
||||
@classmethod
|
||||
|
||||
@@ -81,7 +81,8 @@ def summary(order):
|
||||
document = f'{document[:2]}.{document[2:5]}.{document[5:8]}/{document[8:12]}-{document[12:]}'
|
||||
elif len(document) == 11:
|
||||
document = f'{document[:3]}.{document[3:6]}.{document[6:9]}-{document[9:]}'
|
||||
lines = [f"Cliente: {document} · {customer.get('mail', '')}"]
|
||||
who = ' · '.join(part for part in (customer.get('name'), document, customer.get('mail', '')) if part)
|
||||
lines = [f"Cliente: {who}"]
|
||||
for item in order.get('items', []):
|
||||
metres = item.get('billed_metres') or item.get('metres')
|
||||
lines.append(f"{PRODUCTS.get(item.get('mode'), item.get('mode'))} · {str(metres).replace('.', ',')} m")
|
||||
|
||||
@@ -360,12 +360,14 @@ def money(cents):
|
||||
|
||||
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 recipient or the e-mail. A CPF
|
||||
(11 digits) is a person (F), a CNPJ a company (J)."""
|
||||
registry gave it (app/cnpj.py), else the customer's name, else the
|
||||
recipient or the e-mail. A CPF (11 digits) is a person (F), a CNPJ a
|
||||
company (J)."""
|
||||
customer = order['customer']
|
||||
destination = order.get('destination')
|
||||
company = company or {}
|
||||
contact = {'nome': company.get('legal') or (destination or {}).get('recipient') or customer['mail'],
|
||||
contact = {'nome': (company.get('legal') or customer.get('name') or (destination or {}).get('recipient')
|
||||
or customer['mail']),
|
||||
'tipoPessoa': 'F' if len(customer['cnpj']) == 11 else 'J', 'cpfCnpj': customer['cnpj'], 'email': customer['mail'],
|
||||
'celular': customer['zap'], 'situacao': 'A'}
|
||||
if company.get('trade'):
|
||||
|
||||
Reference in New Issue
Block a user