fix: hide operators' internal back-move reasons from the customer's order history
A move back undoes an operator's mistake and its reason is internal. The customer's history now omits back moves and shows a reason only for a correction; the smoke test checks both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -98,7 +98,10 @@ def orders(identity=Depends(owner)):
|
||||
def detail(oid: UUID, identity=Depends(owner)):
|
||||
with db.connect() as c:
|
||||
row = owned_order(c, oid, identity)
|
||||
history = c.execute('SELECT from_state,to_state,reason,created_at FROM dtf_local.movements WHERE order_id=%s ORDER BY id', (oid,)).fetchall()
|
||||
# A move back undoes an operator's mistake and its reason is internal;
|
||||
# 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'],
|
||||
'snapshot': row['snapshot'], 'history': history, 'files': file_rows(c,oid)}
|
||||
|
||||
|
||||
@@ -195,6 +195,11 @@ def run():
|
||||
client.call('/operator/orders/'+oid+'/move',{'state':'fin','version':version},operator=True);version+=1
|
||||
history=client.call('/operator/orders/'+oid+'/history',operator=True)
|
||||
assert len(history)==8 and history[-2]['back'] and history[-2]['reason']=='Movido por engano' and not history[-1]['back']
|
||||
# The customer sees the stages and the correction's reason, never the
|
||||
# internal reason for going back.
|
||||
seen=client.call('/customer/orders/'+oid)['history']
|
||||
assert len(seen)==7 and all(h['reason']=='' or h['to_state']=='cor' for h in seen)
|
||||
assert any(h['to_state']=='cor' and h['reason']=='Local test correction' for h in seen)
|
||||
print('PASS: a mistaken move is undone one stage back with a reason, without messaging the customer again')
|
||||
print('PASS: all modes, authoritative review/prices/freight, tamper rejection, concurrent payment idempotency, transitions and history')
|
||||
deadline=time.monotonic()+30
|
||||
|
||||
Reference in New Issue
Block a user