feat: customers see an order code, not the sequential number
Some checks failed
Some checks failed
"Minha conta" lists and opens orders as "Pedido 1E867B56" (the first 8 characters of the order's id) and searches by that code, so a customer never sees how many orders the store has. The Kanban shows the code beside the # number, with a copy button, and its search finds an order by the code a customer reads out. Tiny keeps its reference (DTF-<number>): it is how a resent order is found there instead of duplicated, and the WhatsApp notices the client sends from Tiny use Tiny's own number. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ from ..artwork import submit_files
|
||||
from ..core.auth import (DUMMY_PASSWORD_HASH, audit, client_ip, new_session, owner,
|
||||
login_failed, password_hash, password_matches, session_row, throttle, transfer_guest)
|
||||
from ..core.models import ArtworkSubmission, EmailChange, Login, PasswordChange, ProfileUpdate, Register
|
||||
from ..runtime import STATES, file_rows, owned_order, storage
|
||||
from ..runtime import STATES, file_rows, order_code, owned_order, storage
|
||||
from ..scanning import require_clean
|
||||
|
||||
router = APIRouter()
|
||||
@@ -166,14 +166,17 @@ ENTRIES = '''WITH live_quote AS (
|
||||
|
||||
@router.get('/api/customer/orders')
|
||||
def orders(identity=Depends(owner), status: Literal['all','pay','prod','cor','fin'] = 'all',
|
||||
number: int | None = Query(None, ge=1), days: int = Query(0, ge=0, le=3650),
|
||||
number: int | None = Query(None, ge=1), code: str | None = Query(None, max_length=12, pattern=r'^[0-9A-Fa-f]+$'),
|
||||
days: int = Query(0, ge=0, le=3650),
|
||||
page: int = Query(1, ge=1, le=10000), size: int = Query(10, ge=1, le=50)):
|
||||
"""The customer's orders and the cart waiting for payment, newest first,
|
||||
filtered and a page at a time, with how many there are in each group."""
|
||||
params = {'me': identity, 'grp': None if status == 'all' else status, 'number': number,
|
||||
'code': code.lower() + '%' if code else None,
|
||||
'since': datetime.now(timezone.utc) - timedelta(days=days) if days else None,
|
||||
'size': size, 'offset': (page - 1) * size}
|
||||
where = '''WHERE (%(grp)s::text IS NULL OR grp=%(grp)s) AND (%(number)s::int IS NULL OR number=%(number)s)
|
||||
AND (%(code)s::text IS NULL OR (kind='order' AND replace(id::text,'-','') LIKE %(code)s))
|
||||
AND (%(since)s::timestamptz IS NULL OR created_at>=%(since)s)'''
|
||||
with db.connect() as c:
|
||||
counts = {r['grp']: r['n'] for r in c.execute(ENTRIES + ' SELECT grp, count(*) AS n FROM entries GROUP BY grp', params).fetchall()}
|
||||
@@ -183,6 +186,7 @@ def orders(identity=Depends(owner), status: Literal['all','pay','prod','cor','fi
|
||||
items = []
|
||||
for r in rows:
|
||||
entry = {'kind': r['kind'], 'id': r['id'], 'number': r['number'], 'state': r['state'],
|
||||
'code': order_code(r['id']) if r['kind'] == 'order' else None,
|
||||
'group': r['grp'], 'total_cents': r['total_cents'], 'created_at': r['created_at'],
|
||||
'items': [{'mode': i['mode'], 'billed_metres': i.get('billed_metres')} for i in r['items']]}
|
||||
if r['kind'] == 'quote':
|
||||
@@ -203,7 +207,8 @@ def detail(oid: UUID, identity=Depends(owner)):
|
||||
# only a correction's reason is written for the customer.
|
||||
history = c.execute('''SELECT from_state,to_state,CASE WHEN to_state='cor' THEN reason ELSE '' END AS reason,
|
||||
created_at FROM dtf_local.movements WHERE order_id=%s AND NOT back ORDER BY id''', (oid,)).fetchall()
|
||||
return {'id': row['id'], 'number': row['number'], 'state': row['state'], 'version': row['version'],
|
||||
return {'id': row['id'], 'number': row['number'], 'code': order_code(row['id']),
|
||||
'state': row['state'], 'version': row['version'],
|
||||
'created_at': row['created_at'], 'snapshot': row['snapshot'], 'history': history,
|
||||
'files': file_rows(c,oid)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user