Fix #630: Overhaul Historical Currency Revaluation Engine #631
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #630
π οΈ Summary of Changes
models/Transaction.js
: Expanded the schema with forexMetadata (accuracy tracking) and revaluationHistory (audit trails) to support retroactive value corrections.
utils/currencyMath.js
(NEW): Created a high-precision financial utility for standardized rounding, weighted average rates, and FX impact formulas.
services/forexService.js
: Enhanced with a historicalCache and batch synchronization logic to handle large-scale historical rate lookups efficiently.
services/revaluationService.js
: Completely rewritten. It now supports Point-of-Sale vs. Report-Time valuation, weighted average acquisition cost, and a retroactive backfilling engine.
services/batchProcessor.js
(NEW): Implemented an asynchronous job runner to handle massive revaluation tasks (e.g., re-calculating thousands of past transactions) in the background with status tracking.
routes/transactions.js
: Added new API endpoints:
POST /revalue: Trigger background revaluation jobs.
GET /revalue/status/:jobId: Monitor job progress.
GET /:id/revaluation-history: View audit trails for specific transactions.
services/transactionService.js
: Updated the creation pipeline to automatically prime historical metadata for every new multi-currency transaction.
tests/revaluation.test.js
(NEW): Added a comprehensive unit test suite covering the math, logic, and date normalization of the revaluation engine.
HISTORICAL_REVALUATION_DOCUMENTATION.md
(NEW): Created detailed technical documentation to satisfy open-source contribution standards.