Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Hide synced balance updates from linked account activity by default (#4949)

adam2504ce87fb709e99
diff --git a/app/components/UI/account/activity_feed.html.erb b/app/components/UI/account/activity_feed.html.erb
index 459834849f..9834b435c8 100644
--- a/app/components/UI/account/activity_feed.html.erb
+++ b/app/components/UI/account/activity_feed.html.erb
@@ -81,7 +81,8 @@
<%= render "transactions/searches/menu",
form: form,
exclude: [ "account_filter", "ai_filter" ],
- clear_filters_path: helpers.account_path(account, tab: "activity") %>
+ clear_filters_path: helpers.account_path(account, tab: "activity"),
+ balance_updates: balance_updates_filter? %>
<% end %>
<% end %>
<% end %>
@@ -119,6 +120,7 @@
<% end %>
<% end %>
</ul>
+
</div>
<% if activity_dates.empty? %>
diff --git a/app/components/UI/account/activity_feed.rb b/app/components/UI/account/activity_feed.rb
index 6572e746e6..79463cf7e7 100644
--- a/app/components/UI/account/activity_feed.rb
+++ b/app/components/UI/account/activity_feed.rb
@@ -28,6 +28,12 @@ class UI::Account::ActivityFeed < ApplicationComponent
feed_data.entries_by_date
end
+ # The Filter menu offers to show synced balance updates on accounts that
+ # hide them by default, once they have any.
+ def balance_updates_filter?
+ account.hides_balance_updates_by_default? && account.entries.balance_updates.exists?
+ end
+
private
def account
feed_data.account
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 93f0cdc8f5..66d1d73918 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -108,7 +108,11 @@ class AccountsController < ApplicationController
Account::ReconciliationIndicator.for_accounts([ @account ])[@account.id]
end
@q = activity_search_params
- entries = @account.entries.excluding_split_parents.search(@q, family).reverse_chronological.includes(:entryable)
+ # The account and its provider links are preloaded once for every row: a
+ # balance update's label depends on whether the account is linked.
+ entries = @account.entries.excluding_split_parents.search(@q.except(:balance_updates), family).reverse_chronological
+ .includes(:entryable, account: [ :account_providers, :plaid_account, :simplefin_account ])
+ entries = entries.excluding_balance_updates unless show_balance_updates?
if statement_tab_active?
build_statement_tab_data
return render_statement_tab_frame if statement_tab_frame_request?
@@ -451,13 +455,23 @@ class AccountsController < ApplicationController
def activity_search_params
q = params.fetch(:q, {}).permit(
- :search, :start_date, :end_date, :amount, :amount_operator,
+ :search, :start_date, :end_date, :amount, :amount_operator, :balance_updates,
categories: [], tags: [], merchants: [], types: [], status: [], reconcile_status: []
)
q.delete(:amount_operator) unless q[:amount].present?
q
end
+ # Balance updates appear in the feed unless the account hides them by
+ # default (see Account#hides_balance_updates_by_default?). The user can
+ # keep them shown in Settings > Preferences, or show them for one view
+ # with the activity Filter menu (q[balance_updates]=show).
+ def show_balance_updates?
+ [email protected]_balance_updates_by_default? ||
+ Current.user.show_balance_updates? ||
+ @q[:balance_updates] == "show"
+ end
+
# Shares the "per page" preference with TransactionsController's
# prev_transaction_page_params so the page size the user picks on either
# the account activity feed or the global transactions page applies to both.
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 6faa70e2cb..3a3b0db162 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -27,7 +27,10 @@ class UsersController < ApplicationController
end
else
was_ai_enabled = @user.ai_enabled
- if @user.update(user_params.except(:redirect_to, :delete_profile_image))
+ # Lives in the preferences JSON, written under a row lock so concurrent
+ # preference writes aren't lost, rather than through update below.
+ @user.update_show_balance_updates(user_params[:show_balance_updates]) if user_params.key?(:show_balance_updates)
+ if @user.update(user_params.except(:redirect_to, :delete_profile_image, :show_balance_updates))
@user.profile_image.purge if should_purge_profile_image?
# Add a special notice if AI was just enabled or disabled
@@ -124,7 +127,7 @@ class UsersController < ApplicationController
params.require(:user).permit(
:first_name, :last_name, :email, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at,
:show_sidebar, :default_period, :default_account_order, :show_ai_sidebar, :ai_enabled, :theme, :set_onboarding_preferences_at, :set_onboarding_goals_at, :locale,
- :rule_prompts_disabled,
+ :rule_prompts_disabled, :show_balance_updates,
family_attributes: family_attrs,
goals: []
)
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/transactions_helper.rb
index f8b69d00b0..790254f36c 100644
--- a/app/helpers/transactions_helper.rb
+++ b/app/helpers/transactions_helper.rb
@@ -2,9 +2,11 @@ module TransactionsHelper
# @param exclude [Array<String>] filter keys to leave out (e.g. the account
# tab doesn't apply to the account activity feed, which is already scoped
# to one account)
+ # @param balance_updates [Boolean] offer the filter that shows a linked
+ # account's synced balance updates (account activity feed only)
# @return [Array<Hash>] the filters offered above the transaction list, each
# with the key its partial is named for, a translated label and an icon
- def transaction_search_filters(exclude: [])
+ def transaction_search_filters(exclude: [], balance_updates: false)
filters = [
{ key: "account_filter", label: t("transactions.search.filters.account"), icon: "layers" },
{ key: "date_filter", label: t("transactions.search.filters.date"), icon: "calendar" },
@@ -22,6 +24,10 @@ module TransactionsHelper
filters.insert(4, { key: "reconcile_status_filter", label: t("transactions.search.filters.reconcile_status"), icon: "check-circle" })
end
+ if balance_updates
+ filters << { key: "balance_updates_filter", label: t("transactions.search.filters.balance_updates"), icon: "scale" }
+ end
+
filters.reject { |filter| exclude.include?(filter[:key]) }
end
diff --git a/app/models/account.rb b/app/models/account.rb
index 6a568e6d1b..4f63cc5bfc 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -936,6 +936,16 @@ class Account < ApplicationRecord
end
end
+ # Whether the activity feed hides balance updates unless asked to show them.
+ #
+ # A linked account gets one from almost every daily sync, and users can't add
+ # their own there, so they bury the transactions they sit between. Property,
+ # vehicle, loan and other non-cash accounts are valued by those entries, so
+ # they keep showing them.
+ def hides_balance_updates_by_default?
+ linked? && balance_type != :non_cash
+ end
+
def owned_by?(user)
user.present? && owner_id == user.id
end
diff --git a/app/models/entry.rb b/app/models/entry.rb
index 0ba1a278f0..455e53ae66 100644
--- a/app/models/entry.rb
+++ b/app/models/entry.rb
@@ -153,6 +153,24 @@ class Entry < ApplicationRecord
SQL
}
+ # Balance updates: reconciliation valuations. On linked accounts most of them
+ # are the provider's daily balance, kept as a waypoint by
+ # Account::CurrentBalanceManager#preserve_anchor_as_reconciliation_if_stale.
+ # Opening and current anchors are not included.
+ scope :balance_updates, -> {
+ where(entryable_type: "Valuation", entryable_id: Valuation.reconciliation.select(:id))
+ }
+
+ scope :excluding_balance_updates, -> {
+ where(<<~SQL.squish)
+ entries.entryable_type != 'Valuation'
+ OR NOT EXISTS (
+ SELECT 1 FROM valuations v
+ WHERE v.id = entries.entryable_id AND v.kind = 'reconciliation'
+ )
+ SQL
+ }
+
# The entries in `ids` and the children of any of them that was split, which
# stand in for their excluded parent wherever money is counted.
scope :with_split_children, ->(ids) { where(id: ids).or(where(parent_entry_id: ids)) }
diff --git a/app/models/user.rb b/app/models/user.rb
index fbd0098da6..9f6e0a737a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -667,6 +667,20 @@ class User < ApplicationRecord
AccountOrder.find(default_account_order) || AccountOrder.default
end
+ # Whether the activity feed of a linked account always lists the balance
+ # updates its syncs leave behind (see Account#hides_balance_updates_by_default?).
+ # Off until turned on in Settings > Preferences. The activity Filter menu can
+ # show them for one view without changing this.
+ def show_balance_updates?
+ preferences&.dig("show_balance_updates") == true
+ end
+
+ # @param value [Boolean, String] a form value such as "true" or "false"
+ def update_show_balance_updates(value)
+ shown = ActiveModel::Type::Boolean.new.cast(value) == true
+ with_locked_preferences { |prefs| prefs["show_balance_updates"] = shown }
+ end
+
MANUAL_ACCOUNT_ORDER_LIMIT = 500
# Drag-and-drop order of accounts per account group, keyed by accountable
diff --git a/app/models/valuation.rb b/app/models/valuation.rb
index fd042b2897..aae9afab29 100644
--- a/app/models/valuation.rb
+++ b/app/models/valuation.rb
@@ -29,7 +29,10 @@ class Valuation < ApplicationRecord
name = Valuation::Name.new(kind, entry.account.accountable_type)
return entry.name unless entry.name == name.to_s
- translation_key = "valuations.names.#{name.translation_key}"
+ # A reconciliation on a linked account was left by a sync, not typed in,
+ # so it isn't called "manual" there.
+ key = reconciliation? && entry.account.linked? ? name.synced_translation_key : name.translation_key
+ translation_key = "valuations.names.#{key}"
if opening_anchor? &&
!I18n.exists?(translation_key, I18n.locale, fallback: false) &&
I18n.exists?("valuations.show.opening_balance", I18n.locale, fallback: false)
diff --git a/app/models/valuation/name.rb b/app/models/valuation/name.rb
index 525efab98e..e06d31f126 100644
--- a/app/models/valuation/name.rb
+++ b/app/models/valuation/name.rb
@@ -28,6 +28,16 @@ class Valuation::Name
end
end
+ # Returns the I18n key suffix for a reconciliation that a provider sync left
+ # behind (see Account::CurrentBalanceManager#preserve_anchor_as_reconciliation_if_stale).
+ def synced_translation_key
+ case accountable_type
+ when "Property", "Investment", "Vehicle", "Crypto", "OtherAsset" then :synced_value
+ when "Loan" then :synced_principal
+ else :synced_balance
+ end
+ end
+
private
attr_reader :valuation_kind, :accountable_type
diff --git a/app/views/settings/preferences/show.html.erb b/app/views/settings/preferences/show.html.erb
index c3577a2ecf..fe42949e40 100644
--- a/app/views/settings/preferences/show.html.erb
+++ b/app/views/settings/preferences/show.html.erb
@@ -35,6 +35,15 @@
checked: [email protected]_prompts_disabled, checked_value: "false", unchecked_value: "true",
"aria-labelledby": "rule_suggestions_label", data: { auto_submit_form_target: "auto" }) %>
</div>
+ <div class="flex items-center justify-between gap-4">
+ <div class="space-y-1">
+ <p class="text-sm" id="show_balance_updates_label"><%= t(".show_balance_updates") %></p>
+ <p class="text-secondary text-sm"><%= t(".show_balance_updates_hint") %></p>
+ </div>
+ <%= render DS::Toggle.new(id: "user_show_balance_updates", name: "user[show_balance_updates]",
+ checked: @user.show_balance_updates?, checked_value: "true", unchecked_value: "false",
+ "aria-labelledby": "show_balance_updates_label", data: { auto_submit_form_target: "auto" }) %>
+ </div>
<% end %>
</div>
<% end %>
diff --git a/app/views/transactions/searches/_menu.html.erb b/app/views/transactions/searches/_menu.html.erb
index 1db57f86cf..a032757aa4 100644
--- a/app/views/transactions/searches/_menu.html.erb
+++ b/app/views/transactions/searches/_menu.html.erb
@@ -1,5 +1,5 @@
-<%# locals: (form:, exclude: [], clear_filters_path: nil) %>
-<% filters = transaction_search_filters(exclude: exclude) %>
+<%# locals: (form:, exclude: [], clear_filters_path: nil, balance_updates: false) %>
+<% filters = transaction_search_filters(exclude: exclude, balance_updates: balance_updates) %>
<%= render DS::Tabs.new(
variant: :unstyled,
diff --git a/app/views/transactions/searches/filters/_badge.html.erb b/app/views/transactions/searches/filters/_badge.html.erb
index e374b6b255..3fd9c797bd 100644
--- a/app/views/transactions/searches/filters/_badge.html.erb
+++ b/app/views/transactions/searches/filters/_badge.html.erb
@@ -58,6 +58,11 @@
<div class="flex items-center gap-2 px-1">
<p><%= Category.uncategorized_name %></p>
</div>
+ <% elsif param_key == "balance_updates" %>
+ <div class="flex items-center gap-2 px-1">
+ <%= icon("scale", size: "sm") %>
+ <p><%= t(".balance_updates") %></p>
+ </div>
<% elsif param_key == "ai_status" %>
<div class="flex items-center gap-2 px-1">
<%= icon(param_value == "current" ? "sparkles" : "history", size: "sm") %>
diff --git a/app/views/transactions/searches/filters/_balance_updates_filter.html.erb b/app/views/transactions/searches/filters/_balance_updates_filter.html.erb
new file mode 100644
index 0000000000..5a70a445a2
--- /dev/null
+++ b/app/views/transactions/searches/filters/_balance_updates_filter.html.erb
@@ -0,0 +1,22 @@
+<%# locals: (form:) %>
+<%# Shows a linked account's synced balance updates for this view only. Settings > Preferences keeps them shown for good, %>
+<%# and then there is nothing left to switch here. %>
+<% always_shown = Current.user.show_balance_updates? %>
+
+<div class="p-2 space-y-3">
+ <div class="flex items-center gap-3" data-filter-name="balance_updates">
+ <%= form.check_box :balance_updates,
+ {
+ checked: always_shown || @q[:balance_updates] == "show",
+ disabled: always_shown,
+ class: "checkbox checkbox--light"
+ },
+ "show",
+ nil %>
+ <%= form.label :balance_updates, t(".show"), class: "text-sm text-primary" %>
+ </div>
+ <p class="text-secondary text-sm">
+ <%= t(always_shown ? ".always_shown" : ".hint") %>
+ <%= link_to t(".preferences_link"), settings_preferences_path, class: "text-link underline underline-offset-2 hover:no-underline", data: { turbo_frame: "_top" } %>
+ </p>
+</div>
diff --git a/config/locales/views/settings/preferences/en.yml b/config/locales/views/settings/preferences/en.yml
index 84a9483a4d..64383c4fca 100644
--- a/config/locales/views/settings/preferences/en.yml
+++ b/config/locales/views/settings/preferences/en.yml
@@ -3,6 +3,8 @@ en:
settings:
preferences:
show:
+ show_balance_updates: Synced balance updates
+ show_balance_updates_hint: Always list the daily balances that bank syncing records in the activity of linked accounts
country: Country
currency: Currency
date_format: Date format
diff --git a/config/locales/views/settings/preferences/fr.yml b/config/locales/views/settings/preferences/fr.yml
index 6cd38fa7a1..bb3d406c9d 100644
--- a/config/locales/views/settings/preferences/fr.yml
+++ b/config/locales/views/settings/preferences/fr.yml
@@ -3,6 +3,8 @@ fr:
settings:
preferences:
show:
+ show_balance_updates: Mises à jour de solde synchronisées
+ show_balance_updates_hint: "Toujours afficher dans l'activité des comptes connectés les soldes quotidiens enregistrés par la synchronisation"
additional_currencies_label: Devises supplémentaires
base_currency_badge: Devise de base
base_currency_label: Devise de base
diff --git a/config/locales/views/settings/preferences/nl.yml b/config/locales/views/settings/preferences/nl.yml
index 616b0265b8..926bf7900e 100644
--- a/config/locales/views/settings/preferences/nl.yml
+++ b/config/locales/views/settings/preferences/nl.yml
@@ -3,6 +3,8 @@ nl:
settings:
preferences:
show:
+ show_balance_updates: Gesynchroniseerde saldo-updates
+ show_balance_updates_hint: Toon altijd de dagelijkse saldi die de bankkoppeling vastlegt in de activiteit van gekoppelde rekeningen
country: "Land"
currency: "Valuta"
date_format: "Datumformaat"
diff --git a/config/locales/views/settings/preferences/zh-CN.yml b/config/locales/views/settings/preferences/zh-CN.yml
index 230fd24574..4f6b709df5 100644
--- a/config/locales/views/settings/preferences/zh-CN.yml
+++ b/config/locales/views/settings/preferences/zh-CN.yml
@@ -3,6 +3,8 @@ zh-CN:
settings:
preferences:
show:
+ show_balance_updates: 同步余额更新
+ show_balance_updates_hint: 始终在已关联账户的活动中显示银行同步记录的每日余额
country: 国家
currency: 货币
date_format: 日期格式
diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.yml
index c05aca3b68..6cb438e120 100644
--- a/config/locales/views/transactions/en.yml
+++ b/config/locales/views/transactions/en.yml
@@ -295,6 +295,7 @@ en:
toggle_recurring_section: Toggle upcoming recurring transactions
search:
filters:
+ balance_updates: Balances
account: Account
date: Date
type: Type
@@ -350,6 +351,11 @@ en:
unexpected_error: "Unexpected error during conversion: %{error}"
searches:
filters:
+ balance_updates_filter:
+ always_shown: Always shown, as set in
+ hint: For this view only. To always show them, turn them on in
+ preferences_link: Preferences
+ show: Show synced balance updates
account_filter:
filter_accounts: Filter accounts
category_filter:
@@ -367,6 +373,7 @@ en:
less_than: Less than
placeholder: '0'
badge:
+ balance_updates: Synced balances
expense: Expense
income: Income
on_or_after: on or after %{date}
diff --git a/config/locales/views/transactions/fr.yml b/config/locales/views/transactions/fr.yml
index 137df14cf1..5443b8c82c 100644
--- a/config/locales/views/transactions/fr.yml
+++ b/config/locales/views/transactions/fr.yml
@@ -210,6 +210,7 @@ fr:
potential_duplicate_title: Doublon possible détecté
search:
filters:
+ balance_updates: Soldes
account: Compte
ai: IA
amount: Montant
@@ -222,6 +223,11 @@ fr:
type: Type
searches:
filters:
+ balance_updates_filter:
+ always_shown: Toujours affichées, comme réglé dans les
+ hint: Pour cet affichage seulement. Pour toujours les afficher, activez-les dans les
+ preferences_link: Préférences
+ show: Afficher les mises à jour de solde synchronisées
account_filter:
filter_accounts: Filtrer les comptes
ai_filter:
@@ -238,6 +244,7 @@ fr:
with: Avec pièce jointe
without: Sans pièce jointe
badge:
+ balance_updates: Soldes synchronisés
ai_current: IA
ai_history: Historique IA
attachment_with: Avec pièce jointe
diff --git a/config/locales/views/transactions/id.yml b/config/locales/views/transactions/id.yml
index a38555ad77..542d038083 100644
--- a/config/locales/views/transactions/id.yml
+++ b/config/locales/views/transactions/id.yml
@@ -267,6 +267,7 @@ id:
toggle_recurring_section: Alihkan transaksi berulang mendatang
search:
filters:
+ balance_updates: Saldo
account: Rekening
date: Tanggal
type: Jenis
@@ -321,6 +322,11 @@ id:
unexpected_error: "Kesalahan tak terduga saat konversi: %{error}"
searches:
filters:
+ balance_updates_filter:
+ always_shown: Selalu ditampilkan, sesuai pengaturan di
+ hint: Hanya untuk tampilan ini. Agar selalu ditampilkan, aktifkan di
+ preferences_link: Preferensi
+ show: Tampilkan pembaruan saldo tersinkronisasi
account_filter:
filter_accounts: Filter rekening
category_filter:
@@ -338,6 +344,7 @@ id:
less_than: Lebih kecil dari
placeholder: '0'
badge:
+ balance_updates: Saldo tersinkronisasi
expense: Pengeluaran
income: Pemasukan
on_or_after: pada atau setelah %{date}
diff --git a/config/locales/views/transactions/nl.yml b/config/locales/views/transactions/nl.yml
index 6cfd7fc38a..98dcbaf8ab 100644
--- a/config/locales/views/transactions/nl.yml
+++ b/config/locales/views/transactions/nl.yml
@@ -268,6 +268,7 @@ nl:
toggle_recurring_section: "Schakel aankomende terugkerende transacties in/uit"
search:
filters:
+ balance_updates: Saldi
account: "Account"
date: "Datum"
type: "Type"
@@ -322,6 +323,11 @@ nl:
unexpected_error: "Onverwachte fout tijdens conversie: %{error}"
searches:
filters:
+ balance_updates_filter:
+ always_shown: Altijd getoond, ingesteld in
+ hint: Alleen voor deze weergave. Om ze altijd te tonen, zet je ze aan in
+ preferences_link: Voorkeuren
+ show: Gesynchroniseerde saldo-updates tonen
account_filter:
filter_accounts: "Accounts filteren"
category_filter:
@@ -339,6 +345,7 @@ nl:
less_than: "Kleiner dan"
placeholder: "0"
badge:
+ balance_updates: Gesynchroniseerde saldi
expense: "Uitgave"
income: "Inkomsten"
on_or_after: "op of na %{date}"
diff --git a/config/locales/views/transactions/zh-CN.yml b/config/locales/views/transactions/zh-CN.yml
index 6ce47f560c..0efc0087b6 100644
--- a/config/locales/views/transactions/zh-CN.yml
+++ b/config/locales/views/transactions/zh-CN.yml
@@ -260,6 +260,7 @@ zh-CN:
toggle_recurring_section: 切换待发生循环交易
search:
filters:
+ balance_updates: 余额
account: 账户
date: 日期
type: 类型
@@ -315,6 +316,11 @@ zh-CN:
unexpected_error: 转换过程中发生意外错误:%{error}
searches:
filters:
+ balance_updates_filter:
+ always_shown: 已始终显示,设置位于
+ hint: 仅对当前视图生效。如需始终显示,请开启
+ preferences_link: 偏好设置
+ show: 显示同步余额更新
date_filter:
start_date: 开始日期
end_date: 结束日期
@@ -324,6 +330,7 @@ zh-CN:
less_than: 小于
placeholder: '0'
badge:
+ balance_updates: 同步余额
expense: 支出
income: 收入
on_or_after: 于 %{date} 当日或之后
diff --git a/config/locales/views/valuations/en.yml b/config/locales/views/valuations/en.yml
index 265540b5e8..e647b10508 100644
--- a/config/locales/views/valuations/en.yml
+++ b/config/locales/views/valuations/en.yml
@@ -13,6 +13,9 @@ en:
opening_balance: Opening balance
original_principal: Original principal
original_purchase_price: Original purchase price
+ synced_balance: Synced balance
+ synced_principal: Synced principal
+ synced_value: Synced value
confirmation_contents:
this_will: "This will %{action_verb} the account value on"
to_colon: "to:"
diff --git a/config/locales/views/valuations/fr.yml b/config/locales/views/valuations/fr.yml
index 714f30e5cd..f4e77c4e65 100644
--- a/config/locales/views/valuations/fr.yml
+++ b/config/locales/views/valuations/fr.yml
@@ -13,6 +13,9 @@ fr:
opening_balance: Solde d'ouverture
original_principal: Principal initial
original_purchase_price: Prix d'achat initial
+ synced_balance: Solde synchronisé
+ synced_principal: Principal synchronisé
+ synced_value: Valeur synchronisée
confirm_create:
confirm: Confirmer
title: Confirmer le nouveau solde
diff --git a/config/locales/views/valuations/id.yml b/config/locales/views/valuations/id.yml
index a0af62719d..3b15902456 100644
--- a/config/locales/views/valuations/id.yml
+++ b/config/locales/views/valuations/id.yml
@@ -13,6 +13,9 @@ id:
opening_balance: Saldo awal
original_principal: Pokok pinjaman awal
original_purchase_price: Harga pembelian awal
+ synced_balance: Saldo tersinkronisasi
+ synced_principal: Pokok tersinkronisasi
+ synced_value: Nilai tersinkronisasi
confirmation_contents:
this_will: "Ini akan %{action_verb} nilai rekening pada"
to_colon: "menjadi:"
diff --git a/config/locales/views/valuations/nl.yml b/config/locales/views/valuations/nl.yml
index 4de3c77bb7..7166288179 100644
--- a/config/locales/views/valuations/nl.yml
+++ b/config/locales/views/valuations/nl.yml
@@ -13,6 +13,9 @@ nl:
opening_balance: "Beginsaldo"
original_principal: "Oorspronkelijke hoofdsom"
original_purchase_price: "Oorspronkelijke aankoopprijs"
+ synced_balance: "Gesynchroniseerd saldo"
+ synced_principal: "Gesynchroniseerde hoofdsom"
+ synced_value: "Gesynchroniseerde waarde"
confirmation_contents:
this_will: "Hiermee gaat u de accountwaarde %{action_verb} per"
to_colon: "naar:"
diff --git a/config/locales/views/valuations/zh-CN.yml b/config/locales/views/valuations/zh-CN.yml
index 7535bc8565..66cf38a9c1 100644
--- a/config/locales/views/valuations/zh-CN.yml
+++ b/config/locales/views/valuations/zh-CN.yml
@@ -13,6 +13,9 @@ zh-CN:
opening_balance: 期初余额
original_principal: 初始本金
original_purchase_price: 初始购买价格
+ synced_balance: 同步余额
+ synced_principal: 同步本金
+ synced_value: 同步估值
confirmation_contents:
this_will: "这将%{action_verb}账户在"
to_colon: "改为:"
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index 6e67c5161e..db18b03a07 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -578,6 +578,79 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_select "##{dom_id(valuation)}", count: 0
end
+ test "show hides balance updates on a linked account by default" do
+ account = accounts(:connected)
+ transaction = create_transaction(account: account, name: "Linked Transaction")
+ balance_update = create_valuation(account: account, date: 2.days.ago.to_date)
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "##{dom_id(transaction)}"
+ assert_select "##{dom_id(balance_update)}", count: 0
+ assert_select "#transaction-filters-menu button[data-id=?]", "balance_updates_filter", count: 1
+ assert_select "input[type=checkbox][name=?]:not([checked])", "q[balance_updates]"
+ end
+
+ test "show lists balance updates on a linked account when the preference is on" do
+ account = accounts(:connected)
+ balance_update = create_valuation(account: account, date: 2.days.ago.to_date, name: "Manual balance update")
+ @user.update_show_balance_updates(true)
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "##{dom_id(balance_update)}", text: /Synced balance/
+ # Nothing left to switch in the filter: it shows as on, and points to Preferences.
+ assert_select "input[type=checkbox][name=?][checked][disabled]", "q[balance_updates]"
+ assert_select "#account-activity-filters li", count: 0
+ end
+
+ test "the activity filter shows balance updates for one view without saving the preference" do
+ account = accounts(:connected)
+ balance_update = create_valuation(account: account, date: 2.days.ago.to_date)
+
+ get account_url(account), params: { q: { balance_updates: "show", search: "Valuation" } }
+
+ assert_response :success
+ assert_select "##{dom_id(balance_update)}"
+ assert_select "#account-activity-filters li", count: 2
+ assert_select "#account-activity-filters li", text: /Synced balances/
+ assert_not @user.reload.show_balance_updates?
+ end
+
+ test "clearing the balance updates badge hides them again and keeps the other filters" do
+ account = accounts(:connected)
+
+ delete clear_filter_account_url(account), params: {
+ q: { balance_updates: "show", search: "Valuation" },
+ param_key: "balance_updates",
+ param_value: "show"
+ }
+
+ assert_redirected_to account_url(account, q: { search: "Valuation" }, tab: "activity", page: nil, per_page: nil)
+ end
+
+ test "show lists balance updates on a manual account without offering the filter" do
+ balance_update = create_valuation(account: @account, date: 2.days.ago.to_date)
+
+ get account_url(@account)
+
+ assert_response :success
+ assert_select "##{dom_id(balance_update)}"
+ assert_select "#transaction-filters-menu button[data-id=?]", "balance_updates_filter", count: 0
+ end
+
+ test "show omits the balance updates filter on a linked account without any" do
+ account = accounts(:connected)
+ account.entries.balance_updates.destroy_all
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "#transaction-filters-menu button[data-id=?]", "balance_updates_filter", count: 0
+ end
+
test "show renders a badge for each active filter" do
get account_url(@account), params: { q: { categories: [ "Food & Drink" ], search: "grocery" } }
diff --git a/test/controllers/settings/preferences_controller_test.rb b/test/controllers/settings/preferences_controller_test.rb
index c9a1a1db25..12ee880741 100644
--- a/test/controllers/settings/preferences_controller_test.rb
+++ b/test/controllers/settings/preferences_controller_test.rb
@@ -31,6 +31,15 @@ class Settings::PreferencesControllerTest < ActionDispatch::IntegrationTest
assert_match I18n.t("settings.preferences.show.investment_contributions_as_spending"), response.body
end
+ test "every user sees the synced balance updates toggle, off by default" do
+ sign_in users(:family_member)
+ get settings_preferences_url
+
+ assert_response :success
+ assert_select "input[type=checkbox][name='user[show_balance_updates]']:not([checked])"
+ assert_match I18n.t("settings.preferences.show.show_balance_updates"), response.body
+ end
+
test "members do not see the investing-as-spending toggle" do
sign_in users(:family_member)
get settings_preferences_url
diff --git a/test/controllers/transactions/filters_controller_test.rb b/test/controllers/transactions/filters_controller_test.rb
index 6a8c27d0e4..723fd93e76 100644
--- a/test/controllers/transactions/filters_controller_test.rb
+++ b/test/controllers/transactions/filters_controller_test.rb
@@ -39,6 +39,13 @@ class Transactions::FiltersControllerTest < ActionDispatch::IntegrationTest
assert_equal parent_index + 1, child_index
end
+ test "does not offer the balance updates filter, which only applies to an account's activity" do
+ get filters_transactions_url, headers: { "Turbo-Frame" => "transaction-filters" }
+
+ assert_response :success
+ assert_select "#transaction-filters-menu button[data-id=?]", "balance_updates_filter", count: 0
+ end
+
test "offers the attachment filter in the filter menu" do
get filters_transactions_url, headers: { "Turbo-Frame" => "transaction-filters" }
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
index ea3b0c05ba..14b94632cc 100644
--- a/test/controllers/users_controller_test.rb
+++ b/test/controllers/users_controller_test.rb
@@ -119,6 +119,29 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert @user.family.reload.manual_reconciliation?
end
+ test "any member can turn synced balance updates on and off for themselves" do
+ sign_in @member = users(:family_member)
+
+ patch user_url(@member), params: { user: { redirect_to: "preferences", show_balance_updates: "true" } }
+
+ assert_redirected_to settings_preferences_url
+ assert @member.reload.show_balance_updates?
+ assert_not @user.reload.show_balance_updates?
+
+ patch user_url(@member), params: { user: { redirect_to: "preferences", show_balance_updates: "false" } }
+
+ assert_not @member.reload.show_balance_updates?
+ end
+
+ test "turning on synced balance updates keeps the other preferences" do
+ @user.update!(preferences: (@user.preferences || {}).merge("section_order" => [ "net_worth" ]))
+
+ patch user_url(@user), params: { user: { redirect_to: "preferences", show_balance_updates: "true" } }
+
+ assert @user.reload.show_balance_updates?
+ assert_equal [ "net_worth" ], @user.preferences["section_order"]
+ end
+
test "non-admin cannot enable manual reconciliation" do
sign_in @member = users(:family_member)
diff --git a/test/models/account_test.rb b/test/models/account_test.rb
index bce1d63abf..1420698483 100644
--- a/test/models/account_test.rb
+++ b/test/models/account_test.rb
@@ -10,6 +10,22 @@ class AccountTest < ActiveSupport::TestCase
@member = users(:family_member)
end
+ test "linked cash and investment accounts hide balance updates by default" do
+ assert accounts(:connected).hides_balance_updates_by_default?
+
+ investment = accounts(:investment)
+ investment.stubs(:linked?).returns(true)
+ assert investment.hides_balance_updates_by_default?
+ end
+
+ test "manual accounts and linked non-cash accounts show balance updates" do
+ assert_not accounts(:depository).hides_balance_updates_by_default?
+
+ property = accounts(:property)
+ property.stubs(:linked?).returns(true)
+ assert_not property.hides_balance_updates_by_default?
+ end
+
test "can destroy" do
assert_difference "Account.count", -1 do
@account.destroy
diff --git a/test/models/entry_test.rb b/test/models/entry_test.rb
index d4f1a2854e..64faa6c607 100644
--- a/test/models/entry_test.rb
+++ b/test/models/entry_test.rb
@@ -419,4 +419,17 @@ class EntryTest < ActiveSupport::TestCase
entry.update!(entryable_attributes: { id: entry.entryable_id, exchange_rate: 1.2 })
assert entry.saved_changes_affect_balances?
end
+
+ test "balance update scopes split reconciliations from every other entry" do
+ account = accounts(:connected)
+ account.entries.destroy_all
+ transaction = create_transaction(account: account)
+ reconciliation = create_valuation(account: account, date: 2.days.ago.to_date)
+ opening_anchor = create_valuation(account: account, date: 10.days.ago.to_date, kind: "opening_anchor")
+ current_anchor = create_valuation(account: account, date: Date.current, kind: "current_anchor")
+
+ assert_equal [ reconciliation ], account.entries.balance_updates.to_a
+ assert_equal [ transaction, opening_anchor, current_anchor ].map(&:id).sort,
+ account.entries.excluding_balance_updates.pluck(:id).sort
+ end
end
diff --git a/test/models/valuation_test.rb b/test/models/valuation_test.rb
index a454784403..5ca3353559 100644
--- a/test/models/valuation_test.rb
+++ b/test/models/valuation_test.rb
@@ -10,6 +10,23 @@ class ValuationTest < ActiveSupport::TestCase
end
end
+ test "names a reconciliation on a linked account after the sync that left it" do
+ entry = Entry.new(name: "Manual balance update", account: accounts(:connected))
+ valuation = Valuation.new(kind: "reconciliation")
+
+ assert_equal "Synced balance", valuation.display_name(entry)
+ I18n.with_locale(:fr) do
+ assert_equal "Solde synchronisé", valuation.display_name(entry)
+ end
+ end
+
+ test "keeps the manual name on a manual account and the anchor names on a linked one" do
+ assert_equal "Manual balance update",
+ Valuation.new(kind: "reconciliation").display_name(Entry.new(name: "Manual balance update", account: accounts(:depository)))
+ assert_equal "Current balance",
+ Valuation.new(kind: "current_anchor").display_name(Entry.new(name: "Current balance", account: accounts(:connected)))
+ end
+
test "preserves custom valuation names when rendering" do
entry = Entry.new(name: "Réévaluation annuelle", account: accounts(:investment))
valuation = Valuation.new(kind: "reconciliation")