mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
Fix linked account balance currency mismatch (#566)
* Fix linked account balance currency mismatch When linking accounts from providers (Lunchflow, SimpleFIN, Enable Banking), the initial sync was creating balances before the correct currency was known. This caused: 1. Opening anchor entry created with default currency (USD/EUR) 2. First sync created balances with wrong currency 3. Later syncs created balances with correct currency 4. Both currency balances existed, charts showed wrong (zero) values Changes: - Add `skip_initial_sync` parameter to `Account.create_and_sync` - Skip initial sync for linked accounts (provider sync handles it) - Add currency filter to ChartSeriesBuilder query to only fetch balances matching the account's current currency * Add migration script and add tests * Update schema.rb --------- Signed-off-by: soky srm <sokysrm@gmail.com> Co-authored-by: sokie <sokysrm@gmail.com>
This commit is contained in:
@@ -269,13 +269,17 @@ class EnableBankingItemsController < ApplicationController
|
||||
end
|
||||
|
||||
# Create the internal Account (uses save! internally, will raise on failure)
|
||||
# Skip initial sync - provider sync will handle balance creation with correct currency
|
||||
account = Account.create_and_sync(
|
||||
family: Current.family,
|
||||
name: enable_banking_account.name,
|
||||
balance: enable_banking_account.current_balance || 0,
|
||||
currency: enable_banking_account.currency || "EUR",
|
||||
accountable_type: accountable_type,
|
||||
accountable_attributes: {}
|
||||
{
|
||||
family: Current.family,
|
||||
name: enable_banking_account.name,
|
||||
balance: enable_banking_account.current_balance || 0,
|
||||
currency: enable_banking_account.currency || "EUR",
|
||||
accountable_type: accountable_type,
|
||||
accountable_attributes: {}
|
||||
},
|
||||
skip_initial_sync: true
|
||||
)
|
||||
|
||||
# Link account to enable_banking_account via account_providers
|
||||
|
||||
Reference in New Issue
Block a user