diff --git a/app/api/customer.py b/app/api/customer.py index ff5704b..f3f22e7 100644 --- a/app/api/customer.py +++ b/app/api/customer.py @@ -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)} diff --git a/tests/smoke_test.py b/tests/smoke_test.py index 92510ed..12142ec 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -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