Skip to content

feat(trade-in): vista previa de valoración, estado derivado e idempotencia (v2 · PR B) - #503

Open
PapiCuche wants to merge 6 commits into
masterfrom
feat/tradein-preview
Open

PapiCuche wants to merge 6 commits into
masterfrom
feat/tradein-preview

Conversation

@PapiCuche

Copy link
Copy Markdown
Owner

Qué agrega (Trade-In v2, PR B, ADR #501)

Sólo backend, sin migración y sin cambios en el frontend. La valoración sigue siendo referencial; las pruebas que vigilan esa regla siguen intactas.

1. Vista previa de la valoración

POST assessments/<id>/preview/.

  • Sólo lectura: no escribe nada, ni auditoría, ni foto del cálculo, ni cambio de estado.
  • Respuestas parciales: las acepta y devuelve el valor provisional, los bloqueos y las preguntas que faltan.
  • Mismo resultado que «calcular»: con todas las respuestas, el resultado es idéntico. Se comprobó con cuatro conjuntos de reglas.
  • Bloqueo: con un bloqueo, la valoración es NO APTA y el valor es nulo, nunca cero.
  • Permisos y límites: los mismos permisos y el mismo alcance de empresa y sucursal que «calcular». Tiene su propio límite de 120 por minuto.

2. Estado derivado

stage, stage_label y progress en la valoración y en la cotización. Representan los 8 estados del propietario, de BORRADOR a CANCELADO, a partir de los datos que ya existen, sin agregar estados nuevos. En los listados no se agrega ninguna consulta por fila.

3. Doble envío de las comprobaciones

Idempotency-Key opcional en POST checks/:

  • Misma clave y mismo contenido: devuelve la misma comprobación (replayed: true).
  • Misma clave con otro contenido: responde 409.
  • Ventana: 24 horas, por persona y por empresa.
  • Auditoría: guarda sólo la huella de la clave.
  • Sin clave: se mantiene el comportamiento anterior.

Pruebas

  • store.test_trade_in_preview: 26 pruebas.
  • store.test_trade_in_check_idempotency: 13 pruebas, incluida concurrencia real.
  • Todas las suites de parte de pago: 340 pruebas.
  • makemigrations --check limpio.

El despliegue necesita un GO propio.

🤖 Generated with Claude Code

PapiCuche and others added 6 commits December 5, 2026 18:51
…eation

- POST assessments/<id>/preview/: what calculating would freeze now, written
  nowhere (no row, audit, lock or state). Partial and tentative answers are
  counted and the open questions, missing customer, blocking reasons and
  pending checks are named. With every answer present its calculation is
  exactly the calculation. Same capability, reach and editable states as
  calculate; own rate (admin_trade_in_preview).
- stage/stage_label/stage_detail: the owner's eight stages derived from the
  assessment and its current quote revision (trade_in_stage), no new state;
  progress (answered/total) on detail payloads.
- Optional Idempotency-Key on POST checks/: a retry of the same request by the
  same person within 24 h answers the original check (200, replayed); the key
  on another request is a 409. Only the key's keyed digest is kept, in the
  creation audit. Without a key the behaviour is unchanged.

No migration, no frontend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…row queries

- preview: answers that differ from the saved ones return unsaved_changes and
  keep the result provisional even when complete (calculate reads only saved
  answers).
- quote list: the current revision's status, validity and eligibility are
  annotated, so a superseded row's stage costs no query.
- stage docstring records the departure from the ADR: calculated but pending
  verification is PENDIENTE DE INSPECCION.
- questions carry their group's closed kind (group_kind) so the guided
  assessment can place each question by kind, never by the group's name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hard weights

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	02_ESTADO_ACTUAL.md
#	07_CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant