Saltar al contenido principal

Document Modules Code Review Checklist

Use this checklist when adding or modifying document types (Sale, Order, Quote, Bill, Invoice, Return, Credit Note) or when changing calculation logic.

Calculation Architecture

  • Uses LineItemTaxService for tax and total calculations (no duplicate logic)
  • Uses product/source tax definitions when available (not just snapshots)
  • Outputs line items in DocumentLineItemShape for consistent frontend display
  • Tax-inclusive: grandTotal = sum(lineGross) (do NOT add tax again)

Validation

  • Header total is computed from line items (never trusted from client)
  • When client sends total: call validateHeaderTotalMatchesLineTotals before persist
  • recomputeAndUpdateOrderTotals (or equivalent) called after every item mutation
  • Sanity check: computed total is finite and non-negative before persist

Tests

  • Integration test verifies totals match for equivalent line items across documents
  • Unit tests cover discount + tax scenarios

References