FactuGES_ERP/docs/customer-invoices/proforma-duplicate-contract.md
david cf07de4836 feat: add proforma customer change evaluation utility
- Implemented `evaluateProformaCustomerChange` function to assess changes in customer details for proforma invoices.
- Introduced types for customer change details, blockers, field differences, and fiscal targets.
- Added utility functions for normalizing text and formatting recipient information.

test: add unit tests for customer payment resolver

- Created tests for `CustomerPaymentResolver` to validate payment term retrieval and handling of inactive terms.
- Ensured proper behavior when clearing payment terms and handling non-existent terms.

test: add unit tests for customer default payment term resolver

- Developed tests for `CustomerDefaultPaymentTermResolver` to verify default payment term resolution logic.
- Included scenarios for creating customers with and without explicit payment term IDs.

feat: implement customer default payment term resolver

- Created `CustomerDefaultPaymentTermResolver` to manage default payment term resolution during customer creation.
- Integrated with company finder and payment resolver services.

test: add unit tests for create customer use case

- Implemented tests for `CreateCustomerUseCase` to ensure correct handling of payment term IDs during customer creation.
- Validated behavior when no explicit payment term ID is provided.

test: add unit tests for update customer use case

- Developed tests for `UpdateCustomerUseCase` to verify payment term handling during customer updates.
- Ensured that inactive payment terms are not assigned and that explicit null values are respected.

feat: add dependency injection for customer company services

- Implemented DI for customer company dependencies to facilitate service resolution.

test: add tests for customer create data utility

- Created tests for `buildCustomerCreateData` to validate payment term handling based on user input.
2026-08-17 11:25:34 +02:00

2.1 KiB

Duplicado de proformas

Endpoint

  • POST /proformas/:proforma_id/duplicate

Semántica

  • Permite duplicar cualquier proforma no eliminada.
  • La proforma origen puede estar archivada.
  • Si la proforma origen está eliminada lógicamente, el endpoint responde como no disponible.
  • El duplicado siempre nace en draft, activo, con archived_at = NULL, deleted_at = NULL y linked_invoice_id = NULL.
  • La numeración siempre es nueva y se consume desde document-series.
  • Se intenta reutilizar la misma serie documental del origen si sigue activa; si no, se usa la serie por defecto de document_type=proforma.
  • target_invoice_series_code solo se conserva si sigue siendo una serie activa de issued_invoice; si no, pasa a NULL.
  • Se copian datos comerciales y fiscales del origen.
  • Si el PaymentTerm original sigue activo, se copia el mismo paymentTermId.
  • Si el PaymentTerm original está inactivo, no se reutiliza como nueva asignación. El duplicado resuelve:
    1. Customer.paymentTermId, solo si está activo
    2. Company.defaultPaymentTermId, solo si está activo
    3. null
  • Si el Customer tiene un plazo inactivo, se ignora para esta nueva asignación.
  • Si Company tiene por datos legacy un default inactivo, no se usa y el flujo cae a null.
  • Se copian las líneas con nuevos IDs y se recalculan impuestos y totales con el motor actual.

Fuente funcional principal para Payment Terms:

Response

  • 201 Created
  • Devuelve el snapshot completo de la nueva proforma.
  • Si el plazo de pago original estaba inactivo y hubo adaptación, la respuesta incluye metadata funcional equivalente a:
payment_term_adaptation:
  null
  o
  {
    source: "inactive_original",
    resolution: "customer" | "company" | "none"
  }

UI

  • Acción de fila Duplicar en /proformas y /proformas/archived.
  • No muestra Duplicar en /proformas/deleted.
  • Tras duplicar redirige a /proformas/:id/edit.
  • Si el plazo original estaba inactivo y fue sustituido o eliminado, la UI informa del ajuste después de duplicar.