fix(imports): import raw balance records#1724
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR extends Family::DataImporter to recognize and import Balance NDJSON records. Balance records are parsed from NDJSON, have their account IDs remapped, and are upserted with numeric fields normalized to decimals. The import sequencing places Balance imports immediately after Accounts, and earliest-date tracking now includes Balance records to ensure account opening balances precede all subsequent activity. ChangesBalance Record Import
Sequence Diagram(s)sequenceDiagram
participant Importer as Family::DataImporter
participant AccountMap as Account ID Map
participant Parser as Date Parser
participant Validator as Field Validator
participant Converter as Decimal Converter
participant Balance as Balance Model
Importer->>Importer: import_balances(records)
loop per Balance record
Importer->>AccountMap: remap account_id
AccountMap-->>Importer: mapped_account_id
Importer->>Parser: parse date string
Parser-->>Importer: parsed_date
Importer->>Validator: check mapped_account, date, balance present
Validator-->>Importer: valid or skip
Importer->>Converter: optional_decimal(cash fields)
Converter-->>Importer: decimalized values
Importer->>Converter: balance_flows_factor_for(value)
Converter-->>Importer: normalized ±1 or 1
Importer->>Balance: find_or_initialize_by(date, currency, account) + assign attrs
Balance-->>Importer: upsert complete
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Clean fix — threading One semantic note on cash_inflows: decimal_or_default(data["cash_inflows"]), # returns 0 when absent
Generated by Claude Code |
Summary
Balanceimport support to match existing raw balance export records.What changed
Family::DataImporternow acceptsBalancerecords and imports them after accounts are remapped.account_id, default missing currency to the target account currency, and skip generated balance columns.Why
Sure exports materialized raw balance history, but importer support previously reconstructed historical values only through valuation-style records. That left exported
Balancerows without a matching restore path.Validation
docker compose -f .devcontainer/docker-compose.yml exec -T app bash -lc 'cd /workspace && bin/rails test test/models/family/data_importer_test.rb test/models/family/data_exporter_test.rb'docker compose -f .devcontainer/docker-compose.yml exec -T app bash -lc 'cd /workspace && bin/rubocop app/models/family/data_importer.rb test/models/family/data_importer_test.rb test/models/family/data_exporter_test.rb'git diff --checkNotes
Summary by CodeRabbit