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.erbindex 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.rbindex 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 < ApplicationComponentfeed_data.entries_by_dateend+ # 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+privatedef accountfeed_data.accountdiff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rbindex 93f0cdc8f5..66d1d73918 100644--- a/app/controllers/accounts_controller.rb+++ b/app/controllers/accounts_controller.rb@@ -108,7 +108,11 @@ class AccountsController < ApplicationControllerAccount::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_datareturn render_statement_tab_frame if statement_tab_frame_request?@@ -451,13 +455,23 @@ class AccountsController < ApplicationControllerdef activity_search_paramsq = 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?qend+ # 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.rbindex 6faa70e2cb..3a3b0db162 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -27,7 +27,10 @@ class UsersController < ApplicationControllerendelsewas_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 < ApplicationControllerparams.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.rbindex 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 TransactionsHelperfilters.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]) }enddiff --git a/app/models/account.rb b/app/models/account.rbindex 6a568e6d1b..4f63cc5bfc 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -936,6 +936,16 @@ class Account < ApplicationRecordendend+ # 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.idenddiff --git a/app/models/entry.rb b/app/models/entry.rbindex 0ba1a278f0..455e53ae66 100644--- a/app/models/entry.rb+++ b/app/models/entry.rb@@ -153,6 +153,24 @@ class Entry < ApplicationRecordSQL}+ # 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.rbindex fbd0098da6..9f6e0a737a 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -667,6 +667,20 @@ class User < ApplicationRecordAccountOrder.find(default_account_order) || AccountOrder.defaultend+ # 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 accountablediff --git a/app/models/valuation.rb b/app/models/valuation.rbindex fd042b2897..aae9afab29 100644--- a/app/models/valuation.rb+++ b/app/models/valuation.rb@@ -29,7 +29,10 @@ class Valuation < ApplicationRecordname = 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.rbindex 525efab98e..e06d31f126 100644--- a/app/models/valuation/name.rb+++ b/app/models/valuation/name.rb@@ -28,6 +28,16 @@ class Valuation::Nameendend+ # 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+privateattr_reader :valuation_kind, :accountable_typediff --git a/app/views/settings/preferences/show.html.erb b/app/views/settings/preferences/show.html.erbindex 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.erbindex 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.erbindex 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.erbnew file mode 100644index 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.ymlindex 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 accountscountry: Countrycurrency: Currencydate_format: Date formatdiff --git a/config/locales/views/settings/preferences/fr.yml b/config/locales/views/settings/preferences/fr.ymlindex 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émentairesbase_currency_badge: Devise de basebase_currency_label: Devise de basediff --git a/config/locales/views/settings/preferences/nl.yml b/config/locales/views/settings/preferences/nl.ymlindex 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 rekeningencountry: "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.ymlindex 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.ymlindex 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 transactionssearch:filters:+ balance_updates: Balancesaccount: Accountdate: Datetype: 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 updatesaccount_filter:filter_accounts: Filter accountscategory_filter:@@ -367,6 +373,7 @@ en:less_than: Less thanplaceholder: '0'badge:+ balance_updates: Synced balancesexpense: Expenseincome: Incomeon_or_after: on or after %{date}diff --git a/config/locales/views/transactions/fr.yml b/config/locales/views/transactions/fr.ymlindex 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: Soldesaccount: Compteai: IAamount: Montant@@ -222,6 +223,11 @@ fr:type: Typesearches: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éesaccount_filter:filter_accounts: Filtrer les comptesai_filter:@@ -238,6 +244,7 @@ fr:with: Avec pièce jointewithout: Sans pièce jointebadge:+ balance_updates: Soldes synchronisésai_current: IAai_history: Historique IAattachment_with: Avec pièce jointediff --git a/config/locales/views/transactions/id.yml b/config/locales/views/transactions/id.ymlindex 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 mendatangsearch:filters:+ balance_updates: Saldoaccount: Rekeningdate: Tanggaltype: 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 tersinkronisasiaccount_filter:filter_accounts: Filter rekeningcategory_filter:@@ -338,6 +344,7 @@ id:less_than: Lebih kecil dariplaceholder: '0'badge:+ balance_updates: Saldo tersinkronisasiexpense: Pengeluaranincome: Pemasukanon_or_after: pada atau setelah %{date}diff --git a/config/locales/views/transactions/nl.yml b/config/locales/views/transactions/nl.ymlindex 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: Saldiaccount: "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 tonenaccount_filter:filter_accounts: "Accounts filteren"category_filter:@@ -339,6 +345,7 @@ nl:less_than: "Kleiner dan"placeholder: "0"badge:+ balance_updates: Gesynchroniseerde saldiexpense: "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.ymlindex 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.ymlindex 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 balanceoriginal_principal: Original principaloriginal_purchase_price: Original purchase price+ synced_balance: Synced balance+ synced_principal: Synced principal+ synced_value: Synced valueconfirmation_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.ymlindex 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'ouvertureoriginal_principal: Principal initialoriginal_purchase_price: Prix d'achat initial+ synced_balance: Solde synchronisé+ synced_principal: Principal synchronisé+ synced_value: Valeur synchroniséeconfirm_create:confirm: Confirmertitle: Confirmer le nouveau soldediff --git a/config/locales/views/valuations/id.yml b/config/locales/views/valuations/id.ymlindex 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 awaloriginal_principal: Pokok pinjaman awaloriginal_purchase_price: Harga pembelian awal+ synced_balance: Saldo tersinkronisasi+ synced_principal: Pokok tersinkronisasi+ synced_value: Nilai tersinkronisasiconfirmation_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.ymlindex 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.ymlindex 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.rbindex 6e67c5161e..db18b03a07 100644--- a/test/controllers/accounts_controller_test.rb+++ b/test/controllers/accounts_controller_test.rb@@ -578,6 +578,79 @@ class AccountsControllerTest < ActionDispatch::IntegrationTestassert_select "##{dom_id(valuation)}", count: 0end+ 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" doget 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.rbindex 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::IntegrationTestassert_match I18n.t("settings.preferences.show.investment_contributions_as_spending"), response.bodyend+ 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" dosign_in users(:family_member)get settings_preferences_urldiff --git a/test/controllers/transactions/filters_controller_test.rb b/test/controllers/transactions/filters_controller_test.rbindex 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::IntegrationTestassert_equal parent_index + 1, child_indexend+ 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" doget filters_transactions_url, headers: { "Turbo-Frame" => "transaction-filters" }diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rbindex ea3b0c05ba..14b94632cc 100644--- a/test/controllers/users_controller_test.rb+++ b/test/controllers/users_controller_test.rb@@ -119,6 +119,29 @@ class UsersControllerTest < ActionDispatch::IntegrationTestassert @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" dosign_in @member = users(:family_member)diff --git a/test/models/account_test.rb b/test/models/account_test.rbindex 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" doassert_difference "Account.count", -1 do@account.destroydiff --git a/test/models/entry_test.rb b/test/models/entry_test.rbindex d4f1a2854e..64faa6c607 100644--- a/test/models/entry_test.rb+++ b/test/models/entry_test.rb@@ -419,4 +419,17 @@ class EntryTest < ActiveSupport::TestCaseentry.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+ endenddiff --git a/test/models/valuation_test.rb b/test/models/valuation_test.rbindex a454784403..5ca3353559 100644--- a/test/models/valuation_test.rb+++ b/test/models/valuation_test.rb@@ -10,6 +10,23 @@ class ValuationTest < ActiveSupport::TestCaseendend+ 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" doentry = Entry.new(name: "Réévaluation annuelle", account: accounts(:investment))valuation = Valuation.new(kind: "reconciliation")