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
LineItemTaxServicefor tax and total calculations (no duplicate logic) - Uses product/source tax definitions when available (not just snapshots)
- Outputs line items in
DocumentLineItemShapefor 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
validateHeaderTotalMatchesLineTotalsbefore 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
- ADR-002: Document Calculations Architecture
DocumentCalculationsModule/LineItemTaxServicedocument-line-item.types.ts