mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Fix false positive inactive hints for SimpleFin accounts during chunked imports (#573)
* Add tests and logic for zero balance handling and inactivity detection - Updated `SimplefinItem::ImporterInactiveTest` to include cases for chunked imports, credit cards, and loans. - Added logic to skip zero balance detection for liability accounts (e.g., credit cards, loans). - Ensured zero balance runs are counted only once per sync to avoid false positives during chunked imports. * Add nil safety --------- Co-authored-by: Josh Waldrep <joshua.waldrep5+github@gmail.com>
This commit is contained in:
@@ -158,6 +158,16 @@ class SimplefinItem::Importer
|
||||
return
|
||||
end
|
||||
|
||||
# Skip zero balance detection for liability accounts (CreditCard, Loan) where
|
||||
# 0 balance with no holdings is normal (paid off card/loan)
|
||||
account_type = simplefin_account.current_account&.accountable_type
|
||||
return if %w[CreditCard Loan].include?(account_type)
|
||||
|
||||
# Only count each account once per sync run to avoid false positives during
|
||||
# chunked imports (which process the same account multiple times)
|
||||
zero_balance_seen_keys << key if zeroish_balance && no_holdings
|
||||
return if zero_balance_seen_keys.count(key) > 1
|
||||
|
||||
if zeroish_balance && no_holdings
|
||||
stats["zero_runs"][key] = stats["zero_runs"][key].to_i + 1
|
||||
# Cap to avoid unbounded growth
|
||||
@@ -173,6 +183,11 @@ class SimplefinItem::Importer
|
||||
end
|
||||
end
|
||||
|
||||
# Track accounts that have been flagged for zero balance in this sync run
|
||||
def zero_balance_seen_keys
|
||||
@zero_balance_seen_keys ||= []
|
||||
end
|
||||
|
||||
# Track seen error fingerprints during a single importer run to avoid double counting
|
||||
def seen_errors
|
||||
@seen_errors ||= Set.new
|
||||
|
||||
Reference in New Issue
Block a user