Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fix reconciliation filter and bulk reconcile transfers [preview] (#5127)

Shibu M4aa97c0bba16
diff --git a/app/components/UI/account/activity_feed.html.erb b/app/components/UI/account/activity_feed.html.erb
index 9834b435c8..899e22eb48 100644
--- a/app/components/UI/account/activity_feed.html.erb
+++ b/app/components/UI/account/activity_feed.html.erb
@@ -78,9 +78,11 @@
) %>
<% popover.with_custom_content do %>
+ <% excluded_filters = [ "account_filter", "ai_filter" ] %>
+ <% excluded_filters << "reconcile_status_filter" unless account.manual? %>
<%= render "transactions/searches/menu",
form: form,
- exclude: [ "account_filter", "ai_filter" ],
+ exclude: excluded_filters,
clear_filters_path: helpers.account_path(account, tab: "activity"),
balance_updates: balance_updates_filter? %>
<% end %>
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 66d1d73918..95d92c9694 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -3,7 +3,7 @@ class AccountsController < ApplicationController
include FilterClearable
before_action :set_account, only: %i[show sparkline sync set_default remove_default clear_filter]
- before_action :set_manageable_account, only: %i[logo_options toggle_active toggle_exclude_from_reports destroy unlink confirm_unlink select_provider]
+ before_action :set_manageable_account, only: %i[logo_options toggle_active toggle_exclude_from_reports reconcile_all destroy unlink confirm_unlink select_provider]
before_action :ensure_linked_account, only: %i[confirm_unlink unlink]
include Periodable
@@ -17,11 +17,6 @@ class AccountsController < ApplicationController
.with_attached_logo
.includes(:accountable, :account_providers, :plaid_account, :simplefin_account)
.order(:name)
- @reconciliation_indicators = if Current.family.manual_reconciliation?
- Account::ReconciliationIndicator.for_accounts(@manual_accounts)
- else
- {}
- end
@financekit_accounts = Current.family.accounts
.where(id: @accessible_account_ids).where.not(status: :pending_deletion)
.joins(:account_providers).where(account_providers: { provider_type: "FinancekitAccountLineage" })
@@ -285,6 +280,29 @@ class AccountsController < ApplicationController
redirect_to accounts_path
end
+ # Sets one reconciliation status for every transaction on a manually entered
+ # account. Statement reconciliation columns stay as they are.
+ def reconcile_all
+ return head :not_found unless Current.family.manual_reconciliation?
+
+ status = params[:reconciled_status].to_s
+
+ unless Entry.reconciled_statuses.key?(status)
+ redirect_to account_path(@account), alert: t("accounts.reconcile_all.invalid_status")
+ return
+ end
+
+ unless @account.manual?
+ redirect_to account_path(@account), alert: t("accounts.reconcile_all.not_manual_account")
+ return
+ end
+
+ updated = Entry.set_reconciled_status_for_account!(@account, status)
+
+ redirect_back_or_to account_path(@account),
+ notice: t("accounts.reconcile_all.success", count: updated, status: t("transactions.reconcile.statuses.#{status}"))
+ end
+
def set_default
unless @account.eligible_for_transaction_default?
redirect_to accounts_path, alert: t("accounts.set_default.depository_only")
@@ -458,6 +476,9 @@ class AccountsController < ApplicationController
:search, :start_date, :end_date, :amount, :amount_operator, :balance_updates,
categories: [], tags: [], merchants: [], types: [], status: [], reconcile_status: []
)
+ # Manual reconciliation only applies to accounts without a live sync.
+ # Ignore a stale or crafted filter on a synced account page.
+ q.delete(:reconcile_status) unless @account&.manual?
q.delete(:amount_operator) unless q[:amount].present?
q
end
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index e2e136d31d..5e3d026b27 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -48,11 +48,6 @@ class PagesController < ApplicationController
@balance_sheet = Current.family.balance_sheet
@investment_statement = Current.family.investment_statement
@accounts = Current.user.accessible_accounts.visible.with_attached_logo
- @reconciliation_indicators = if Current.family.manual_reconciliation?
- Account::ReconciliationIndicator.for_accounts(@accounts)
- else
- {}
- end
@dashboard_view_params = dashboard_view_params
@dashboard_sections, @hidden_dashboard_sections = build_dashboard_sections
diff --git a/app/controllers/transactions/bulk_updates_controller.rb b/app/controllers/transactions/bulk_updates_controller.rb
index eb1ce24e88..4e0eace4f0 100644
--- a/app/controllers/transactions/bulk_updates_controller.rb
+++ b/app/controllers/transactions/bulk_updates_controller.rb
@@ -1,5 +1,12 @@
class Transactions::BulkUpdatesController < ApplicationController
def new
+ # The selection bar sends these flags so the drawer can hide fields that
+ # do not apply to the selected entries. They control display only; the
+ # server still enforces the same rules in Entry.bulk_update!.
+ @has_transaction_entry = params[:has_transaction_entry] != "false"
+ @has_transfer_entry = params[:has_transfer_entry] == "true"
+ @has_category_editable_entry = params[:has_category_editable_entry] != "false"
+ @has_normal_transaction_entry = params[:has_normal_transaction_entry] != "false"
end
def create
@@ -35,6 +42,10 @@ class Transactions::BulkUpdatesController < ApplicationController
annotate_ids = rows.map(&:first).uniq - full_ids
updated = Entry.transaction do
+ # The two groups below lock their rows in different orders. Lock the full
+ # selection first, so requests with opposite permissions cannot deadlock.
+ Entry.lock_for_bulk_update!(full_ids + annotate_ids)
+
bulk_update_entries(full_ids, scoped_params) +
bulk_update_entries(annotate_ids, scoped_params.slice(*AccountShare::ANNOTATE_ENTRY_ATTRIBUTES, *AccountShare::ANNOTATE_TRANSACTION_ATTRIBUTES))
end
diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb
index 84aa67a277..4adf614e9f 100644
--- a/app/helpers/accounts_helper.rb
+++ b/app/helpers/accounts_helper.rb
@@ -70,8 +70,7 @@ module AccountsHelper
.pick(Arel.sql("count(*)"), Arel.sql("max(account_providers.updated_at)"))
[
- family.build_cache_key("account_sidebar_tabs_v7", invalidate_on_data_updates: true),
- family.manual_reconciliation?,
+ family.build_cache_key("account_sidebar_tabs_v8", invalidate_on_data_updates: true),
Current.user&.id,
shares_version,
providers_version,
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/transactions_helper.rb
index 790254f36c..390767fc68 100644
--- a/app/helpers/transactions_helper.rb
+++ b/app/helpers/transactions_helper.rb
@@ -20,7 +20,7 @@ module TransactionsHelper
{ key: "attachment_filter", label: t("transactions.search.filters.attachment"), icon: "paperclip" }
]
- if Current.family&.manual_reconciliation?
+ if manual_reconciliation_filter_available?
filters.insert(4, { key: "reconcile_status_filter", label: t("transactions.search.filters.reconcile_status"), icon: "check-circle" })
end
@@ -31,6 +31,14 @@ module TransactionsHelper
filters.reject { |filter| exclude.include?(filter[:key]) }
end
+ # Whether the reconciliation filter is worth offering. The setting alone is
+ # not enough: the filter only matches manual accounts, so it would return an
+ # empty list for a user with no accessible manual account.
+ def manual_reconciliation_filter_available?
+ Current.family&.manual_reconciliation? &&
+ (Current.user ? Current.user.accessible_accounts.manual.exists? : Current.family.accounts.manual.exists?)
+ end
+
# @param label [String] a stored investment_activity_label such as "Sweep In"
# @return [String] its name in the current locale, or the label itself when
# it has no translation
@@ -162,7 +170,9 @@ module TransactionsHelper
# The "Transfer?" hint is drawn inside the cached row.
@transfer_hint_transaction_ids&.include?(transaction.id) || false,
can_annotate_account?(entry.account),
+ Current.family&.manual_reconciliation?,
can_reconcile_account?(entry.account),
+ (manual_account?(entry.account) if transfer.present?),
counterpart.present? && @accessible_account_ids&.include?(counterpart.id),
Setting.brand_fetch_logo_size,
Setting.brand_fetch_client_id.presence&.then { |id| Digest::SHA256.hexdigest(id) },
@@ -203,6 +213,30 @@ module TransactionsHelper
@reconcilable_account_ids.include?(account.id)
end
+ # Memoized per request so reading the row cache key does not run one
+ # account-provider query per transfer row.
+ def manual_account?(account)
+ return false unless account
+
+ @manual_account_cache ||= {}
+ @manual_account_cache.fetch(account.id) do
+ @manual_account_cache[account.id] = account.manual?
+ end
+ end
+
+ # A matched transfer cannot be bulk edited like a normal entry: its date,
+ # category and merchant belong to the pair or to the outflow leg. The
+ # checkbox is offered only where manual reconciliation is available, and
+ # Edit then exposes the safe fields (name, notes, tags, reconciliation).
+ def bulk_reconcilable_transfer?(entry)
+ transaction = entry.entryable
+
+ transaction&.transfer.present? &&
+ Current.family&.manual_reconciliation? &&
+ manual_account?(entry.account) &&
+ can_reconcile_account?(entry.account)
+ end
+
# The dashboard drill-down filters by account id, so its filter chips name
# the account rather than print the id. Memoized per request like the above.
def transaction_filter_account_name(account_id)
diff --git a/app/javascript/controllers/bulk_select_controller.js b/app/javascript/controllers/bulk_select_controller.js
index cac1867f52..a7d5c41054 100644
--- a/app/javascript/controllers/bulk_select_controller.js
+++ b/app/javascript/controllers/bulk_select_controller.js
@@ -9,6 +9,9 @@ export default class extends Controller {
"selectionBarText",
"bulkEditDrawerHeader",
"duplicateLink",
+ "editLink",
+ "deleteButton",
+ "reconcileMenu",
];
static values = {
singularLabel: String,
@@ -43,7 +46,17 @@ export default class extends Controller {
`${scope}[entry_ids][]`,
this.selectedIdsValue,
);
- form.requestSubmit();
+ // Pass the clicked submit button so Turbo reads a data-turbo-frame on it.
+ // The Delete button is type="button", so it still submits without a
+ // submitter and uses the form's frame.
+ const submitter = e.target.closest(
+ 'button[type="submit"], input[type="submit"]',
+ );
+ if (submitter) {
+ form.requestSubmit(submitter);
+ } else {
+ form.requestSubmit();
+ }
}
togglePageSelection(e) {
@@ -139,10 +152,58 @@ export default class extends Controller {
this.selectionBarTarget.querySelector("input[type='checkbox']").checked =
count > 0;
+ const selectedRows = this._selectedRows();
+ const hasTransfer = selectedRows.some(
+ (row) => row.dataset.transfer === "true",
+ );
+ const hasTransaction = selectedRows.some(
+ (row) => row.dataset.entryType === "Transaction",
+ );
+ const hasCategoryEditable = selectedRows.some(
+ (row) => row.dataset.categoryEditable === "true",
+ );
+ const hasNormalTransaction = selectedRows.some(
+ (row) =>
+ row.dataset.entryType === "Transaction" &&
+ row.dataset.transfer !== "true",
+ );
+
+ if (this.hasEditLinkTarget) {
+ const url = new URL(this.editLinkTarget.href, window.location.origin);
+ url.searchParams.set(
+ "has_transaction_entry",
+ hasTransaction ? "true" : "false",
+ );
+ url.searchParams.set(
+ "has_transfer_entry",
+ hasTransfer ? "true" : "false",
+ );
+ url.searchParams.set(
+ "has_category_editable_entry",
+ hasCategoryEditable ? "true" : "false",
+ );
+ url.searchParams.set(
+ "has_normal_transaction_entry",
+ hasNormalTransaction ? "true" : "false",
+ );
+ this.editLinkTarget.href = url.toString();
+ }
+
+ if (this.hasDeleteButtonTarget) {
+ this.deleteButtonTarget.classList.toggle("hidden", hasTransfer);
+ }
+
+ if (this.hasReconcileMenuTarget) {
+ this.reconcileMenuTarget.classList.toggle("hidden", !hasTransaction);
+ this._updateReconcileForms();
+ }
+
if (this.hasDuplicateLinkTarget) {
const selectedRow = this._selectedRow();
const canDuplicate =
- count === 1 && selectedRow?.dataset.entryType === "Transaction";
+ count === 1 &&
+ selectedRow?.dataset.entryType === "Transaction" &&
+ !hasTransfer;
this.duplicateLinkTarget.classList.toggle("hidden", !canDuplicate);
@@ -173,6 +234,28 @@ export default class extends Controller {
);
}
+ _selectedRows() {
+ return this.rowTargets.filter((row) =>
+ this.selectedIdsValue.includes(row.dataset.id),
+ );
+ }
+
+ // The Reconcile menu items are plain form submissions. Put the selected
+ // ids in each form action so the native submit carries them, without
+ // relying on a click handler to add hidden inputs to a button_to form.
+ _updateReconcileForms() {
+ this.reconcileMenuTarget.querySelectorAll("form").forEach((form) => {
+ const url = new URL(form.action, window.location.origin);
+ url.searchParams.delete("bulk_update[entry_ids][]");
+
+ this.selectedIdsValue.forEach((id) => {
+ url.searchParams.append("bulk_update[entry_ids][]", id);
+ });
+
+ form.action = url.toString();
+ });
+ }
+
_updateGroups() {
this.groupTargets.forEach((group) => {
const rows = this.rowTargets.filter(
diff --git a/app/models/entry.rb b/app/models/entry.rb
index edbf99f802..d25ac3075e 100644
--- a/app/models/entry.rb
+++ b/app/models/entry.rb
@@ -784,6 +784,47 @@ class Entry < ApplicationRecord
30.years.ago.to_date
end
+ # Lock the selected entries before a bulk update. Lock the transactions
+ # first, then the entries. Order each set by id.
+ #
+ # Transfer::Matcher locks in the same order, so a concurrent match cannot
+ # deadlock with a bulk update. Callers that update several permission
+ # groups must lock the full selection here first: per-group locks use
+ # different orders across concurrent requests.
+ #
+ # The ids must already be authorized by the caller.
+ def lock_for_bulk_update!(entry_ids)
+ ids = Array.wrap(entry_ids).compact.uniq
+ return [] if ids.empty?
+
+ transaction_ids = unscoped.where(id: ids, entryable_type: "Transaction").distinct.pluck(:entryable_id)
+ Transaction.where(id: transaction_ids).order(:id).lock.pluck(:id)
+ unscoped.where(id: ids).reorder(:id).lock("FOR UPDATE OF entries").to_a
+ end
+
+ # Sets the manual reconciliation status for every transaction on the
+ # account. Split parents stay out: the activity list hides them and shows
+ # their children instead.
+ #
+ # Lock the entries in ascending id order before the update. Bulk updates
+ # and Transfer::Matcher take entry locks in that order too, so a
+ # concurrent request cannot deadlock with this account-wide write.
+ #
+ # Reconciling is not an edit, so this leaves user_modified and the saved
+ # attributes alone. It does bump updated_at because the cached transaction
+ # row key includes it.
+ def set_reconciled_status_for_account!(account, status)
+ status = status.to_s
+ raise ArgumentError, "Unknown reconciled status: #{status}" unless reconciled_statuses.key?(status)
+
+ scope = where(account: account, entryable_type: "Transaction").excluding_split_parents
+
+ transaction do
+ scope.reorder(:id).lock("FOR UPDATE OF entries").pluck(:id)
+ scope.update_all(reconciled_status: status, updated_at: Time.current)
+ end
+ end
+
# Bulk update entries with the given parameters.
#
# No authorization happens here: callers must scope the relation to entries
@@ -826,7 +867,35 @@ class Entry < ApplicationRecord
rescheduled_ids = []
transaction do
- all.includes(:account).each do |entry|
+ # Lock before reading membership. A concurrent match cannot then turn a
+ # selected entry into a matched leg between the read and the update.
+ selected_entry_ids = all.except(:includes).pluck(:id)
+ locked_entries = lock_for_bulk_update!(selected_entry_ids)
+ ActiveRecord::Associations::Preloader.new(
+ records: locked_entries,
+ associations: [ :account, :entryable ]
+ ).call
+
+ # Resolve the matched-transfer set inside the transaction, after the
+ # locks, so it reflects a match that committed before the lock.
+ transfer_leg_entry_ids =
+ if bulk_attributes[:date].present? || bulk_attributes[:entryable_attributes].present?
+ Entry.unscoped.where(id: locked_entries.map(&:id), entryable_type: "Transaction")
+ .joins("INNER JOIN transactions ON transactions.id = entries.entryable_id")
+ .where(<<~SQL.squish)
+ EXISTS (
+ SELECT 1 FROM transfers
+ WHERE transfers.inflow_transaction_id = transactions.id
+ OR transfers.outflow_transaction_id = transactions.id
+ )
+ SQL
+ .pluck("entries.id")
+ .to_set
+ else
+ Set.new
+ end
+
+ locked_entries.each do |entry|
changed = false
# Whether this row's changes should lock saved attributes / mark
# user-modified. Reconciling is a verification action, not an
@@ -844,7 +913,28 @@ class Entry < ApplicationRecord
attrs.delete(:entryable_attributes) unless entry.transaction?
# reconciled_status is a manual-accounts-only concept — synced accounts
# already have duplicate-matching + statement-level reconciliation.
- attrs.delete(:reconciled_status) unless entry.account.manual?
+ # It is also a transaction concept: valuations and trades have no
+ # badge and the reconciliation indicator never counts them.
+ attrs.delete(:reconciled_status) unless entry.transaction? && entry.account.manual?
+
+ # A matched transfer leg keeps its date, and only the outflow of a
+ # categorizable transfer owns a category. Never apply a merchant
+ # to a transfer. This also preserves the categorize wizard, which
+ # intentionally includes loan_payment and investment_contribution
+ # outflows.
+ if transfer_leg_entry_ids.include?(entry.id)
+ attrs.delete(:date)
+
+ if attrs[:entryable_attributes].present?
+ category_id = attrs[:entryable_attributes][:category_id]
+
+ if category_id.present? && entry.transaction.category_editable?
+ attrs[:entryable_attributes] = { category_id: category_id }
+ else
+ attrs.delete(:entryable_attributes)
+ end
+ end
+ end
if attrs.present?
attrs[:entryable_attributes] = attrs[:entryable_attributes].dup if attrs[:entryable_attributes].present?
@@ -884,7 +974,7 @@ class Entry < ApplicationRecord
# Moving a date changes balances (and may make an entry scheduled), so
# mirror Entry#sync_account_later -- once per account, not per entry.
sync_windows.each { |account, window_start| account.sync_later(window_start_date: window_start) }
- EntryScheduledSyncJob.schedule_for_entries(Entry.where(id: rescheduled_ids)) if rescheduled_ids.any?
+ EntryScheduledSyncJob.schedule_for_entries(Entry.unscoped.where(id: rescheduled_ids)) if rescheduled_ids.any?
updated_count
end
diff --git a/app/models/entry_search.rb b/app/models/entry_search.rb
index 266112e8b6..12e2e4516f 100644
--- a/app/models/entry_search.rb
+++ b/app/models/entry_search.rb
@@ -7,6 +7,7 @@ class EntrySearch
attribute :amount_operator, :string
attribute :types, array: true
attribute :status, array: true
+ attribute :reconcile_status, array: true
attribute :accounts, array: true
attribute :account_ids, array: true
attribute :start_date, :string
@@ -17,9 +18,10 @@ class EntrySearch
attr_reader :family
- # `family` is only required to scope the category-name lookup in
- # Transaction::Search.apply_category_filter (see #1480); every other filter
- # here works without it.
+ # `family` is required to scope the category-name lookup in
+ # Transaction::Search.apply_category_filter (see #1480) and the manual-account
+ # subquery in apply_reconcile_status_filter; every other filter here works
+ # without it.
def initialize(filters = {}, family: nil)
@family = family
super(filters)
@@ -116,7 +118,9 @@ class EntrySearch
if transaction_specific_filters?
# Only Transaction entries have a category/merchant/type/tags, so this
- # join is skipped unless one of those filters is active. Most of
+ # join is skipped unless one of those filters is active. Reconciliation
+ # is also limited to transactions: the badge, the filter and the
+ # reconciliation indicator all treat it as a transaction concept. Most of
# Transaction::Search's apply_* methods exclude non-Transaction entries
# as a side effect of their own conditions, but apply_type_filter
# doesn't when every type is selected (it's a no-op then) — so exclude
@@ -125,6 +129,7 @@ class EntrySearch
query = query.where(entries: { entryable_type: "Transaction" })
query = Transaction::Search.apply_category_filter(query, categories, family)
query = Transaction::Search.apply_type_filter(query, types)
+ query = Transaction::Search.apply_reconcile_status_filter(query, reconcile_status, family)
query = Transaction::Search.apply_merchant_filter(query, merchants)
query = Transaction::Search.apply_tag_filter(query, tags)
end
@@ -134,6 +139,7 @@ class EntrySearch
private
def transaction_specific_filters?
- categories.present? || types.present? || merchants.present? || tags.present?
+ categories.present? || types.present? || merchants.present? || tags.present? ||
+ (Array(reconcile_status) & Entry.reconciled_statuses.keys).any?
end
end
diff --git a/app/models/transaction/search.rb b/app/models/transaction/search.rb
index dd37988cd7..a22af39a00 100644
--- a/app/models/transaction/search.rb
+++ b/app/models/transaction/search.rb
@@ -142,6 +142,30 @@ class Transaction::Search
end
query.where(id: matching_ids)
end
+
+ # Filters by the manual reconciled_status enum (see Entry#reconciled_status).
+ # Scoped to manual accounts — every entry defaults to "unreconciled"
+ # regardless of account type, but the UI/update paths only ever
+ # show/change this for accounts with no live bank sync. Without this
+ # scope, selecting "Unreconciled" would also match every synced
+ # transaction in the family.
+ #
+ # Unlike apply_status_filter (bank-sync pending/confirmed), this is a
+ # user-controlled flag, so any subset of the three values is meaningful —
+ # there's no "all selected = no filter" shortcut.
+ #
+ # Shared with EntrySearch (the account activity page), so `query` need not
+ # be rooted on Transaction. `family` scopes the manual-account subquery.
+ def apply_reconcile_status_filter(query, reconcile_statuses, family)
+ valid_statuses = Array(reconcile_statuses) & Entry.reconciled_statuses.keys
+ return query if valid_statuses.empty?
+ raise ArgumentError, "family is required to filter by reconcile status" if family.nil?
+
+ # Subquery rather than pluck(:id) — avoids loading every manual
+ # account id into Ruby, consistent with the writable-accounts scoping
+ # in Transactions::BulkUpdatesController#create.
+ query.where(entries: { account_id: family.accounts.manual.select(:id), reconciled_status: valid_statuses })
+ end
end
# Automatic-categorization provenance filter values (used by the view)
AI_STATUSES = %w[current history].freeze
@@ -189,7 +213,7 @@ class Transaction::Search
query = self.class.apply_category_filter(query, categories, family)
query = self.class.apply_type_filter(query, types)
query = apply_status_filter(query, status)
- query = apply_reconcile_status_filter(query, reconcile_status)
+ query = self.class.apply_reconcile_status_filter(query, reconcile_status, family)
query = self.class.apply_merchant_filter(query, merchants)
query = self.class.apply_tag_filter(query, tags)
query = apply_ai_status_filter(query, ai_status)
@@ -380,26 +404,4 @@ class Transaction::Search
query
end
end
-
- # Filters by the manual reconciled_status enum (see Entry#reconciled_status).
- # Scoped to manual accounts — every entry defaults to "unreconciled"
- # regardless of account type, but the UI/update paths only ever
- # show/change this for accounts with no live bank sync. Without this
- # scope, selecting "Unreconciled" would also match every synced
- # transaction in the family.
- #
- # Unlike apply_status_filter (bank-sync pending/confirmed), this is a
- # user-controlled flag, so any subset of the three values is meaningful —
- # there's no "all selected = no filter" shortcut.
- def apply_reconcile_status_filter(query, reconcile_statuses)
- return query unless reconcile_statuses.present?
-
- valid_statuses = reconcile_statuses & Entry.reconciled_statuses.keys
- return query if valid_statuses.empty?
-
- # Subquery rather than pluck(:id) — avoids loading every manual
- # account id into Ruby, consistent with the writable-accounts scoping
- # in Transactions::BulkUpdatesController#create.
- query.where(entries: { account_id: family.accounts.manual.select(:id), reconciled_status: valid_statuses })
- end
end
diff --git a/app/views/accounts/_account.html.erb b/app/views/accounts/_account.html.erb
index 8ca2ae870b..f8d0fd74cd 100644
--- a/app/views/accounts/_account.html.erb
+++ b/app/views/accounts/_account.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (account:, return_to: nil, reconciliation_indicator: nil) %>
+<%# locals: (account:, return_to: nil) %>
<% is_default = Current.user&.default_account_id == account.id %>
@@ -9,7 +9,7 @@
data-action="click->clickable-row#open"
<% end %>>
<div class="flex items-center gap-3">
- <%= render "accounts/logo", account: account, size: "md", reconciliation_indicator: reconciliation_indicator %>
+ <%= render "accounts/logo", account: account, size: "md" %>
<div>
<% if account.pending_deletion? %>
diff --git a/app/views/accounts/_account_sidebar_tabs.html.erb b/app/views/accounts/_account_sidebar_tabs.html.erb
index 1e8d83d9a1..a811b33c6b 100644
--- a/app/views/accounts/_account_sidebar_tabs.html.erb
+++ b/app/views/accounts/_account_sidebar_tabs.html.erb
@@ -4,17 +4,12 @@
ERB dependency tracker mis-parses as a bogus "Ds/D" template dependency
and then logs "Couldn't find template for digesting: Ds/D" on every cache
miss. The cache key is already manually versioned via
- account_sidebar_tabs_cache_key ("account_sidebar_tabs_v7",
+ account_sidebar_tabs_cache_key ("account_sidebar_tabs_v8",
invalidate_on_data_updates: true), so we opt out of automatic template
digesting. Bump that version suffix when changing this template or its
sidebar dependencies. %>
<% cache account_sidebar_tabs_cache_key(family: family, active_tab: active_tab, mobile: mobile), expires_in: 12.hours, skip_digest: true do %>
<% sortable = Current.user&.account_order&.manual? %>
-<% reconciliation_indicators = if family.manual_reconciliation?
- Account::ReconciliationIndicator.for_accounts(family.balance_sheet.account_groups.flat_map(&:accounts))
- else
- {}
- end %>
<%= tag.div id: "account-sidebar-tabs",
data: sortable ? {
controller: "account-sort-mode",
@@ -62,7 +57,7 @@
<div>
<% family.balance_sheet.assets.account_groups.each do |group| %>
- <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable, reconciliation_indicators: reconciliation_indicators %>
+ <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable %>
<% end %>
</div>
</div>
@@ -94,7 +89,7 @@
<div>
<% family.balance_sheet.liabilities.account_groups.each do |group| %>
- <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable, reconciliation_indicators: reconciliation_indicators %>
+ <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable %>
<% end %>
</div>
</div>
@@ -126,7 +121,7 @@
<div>
<% family.balance_sheet.account_groups.each do |group| %>
- <%= render "accounts/accountable_group", account_group: group, mobile: mobile, all_tab: true, sortable: sortable, reconciliation_indicators: reconciliation_indicators %>
+ <%= render "accounts/accountable_group", account_group: group, mobile: mobile, all_tab: true, sortable: sortable %>
<% end %>
</div>
</div>
diff --git a/app/views/accounts/_accountable_group.html.erb b/app/views/accounts/_accountable_group.html.erb
index 87d91b52db..28668cf01a 100644
--- a/app/views/accounts/_accountable_group.html.erb
+++ b/app/views/accounts/_accountable_group.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (account_group:, mobile: false, all_tab: false, open: nil, sortable: false, reconciliation_indicators: {}, **args) %>
+<%# locals: (account_group:, mobile: false, all_tab: false, open: nil, sortable: false, **args) %>
<div id="<%= account_group.dom_id(tab: all_tab ? :all : nil, mobile: mobile) %>" data-group-key="<%= account_group.key %>">
<% is_open = open.nil? ? (account_group.accounts.any? { |account| page_active?(account_path(account)) } || Current.user.always_expanded_account_group?(account_group.key)) : open %>
@@ -65,7 +65,7 @@
),
data: page_active?(account_path(account)) ? { active_account: true } : {},
title: account.name do %>
- <%= render "accounts/logo", account: account, size: "sm", color: account_group.color, reconciliation_indicator: reconciliation_indicators[account.id] %>
+ <%= render "accounts/logo", account: account, size: "sm", color: account_group.color %>
<div class="min-w-0 grow">
<div class="flex items-center gap-2 mb-0.5">
diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb
index 5ae5883561..9eeec24b04 100644
--- a/app/views/accounts/index.html.erb
+++ b/app/views/accounts/index.html.erb
@@ -186,7 +186,7 @@
<% if @manual_accounts.any? %>
<div id="manual-accounts">
- <%= render "accounts/index/manual_accounts", accounts: @manual_accounts, reconciliation_indicators: @reconciliation_indicators %>
+ <%= render "accounts/index/manual_accounts", accounts: @manual_accounts %>
</div>
<% else %>
<div id="manual-accounts"></div>
diff --git a/app/views/accounts/index/_account_groups.erb b/app/views/accounts/index/_account_groups.erb
index 7e4a5c1a50..2f1ecef360 100644
--- a/app/views/accounts/index/_account_groups.erb
+++ b/app/views/accounts/index/_account_groups.erb
@@ -1,4 +1,4 @@
-<%# locals: (accounts:, reconciliation_indicators: {}) %>
+<%# locals: (accounts:) %>
<% if accounts.any? %>
<% ActiveRecord::Associations::Preloader.new(
@@ -26,7 +26,7 @@
</div>
<div class="bg-container rounded-lg shadow-border-xs overflow-hidden">
<% accounts.each_with_index do |account, index| %>
- <%= render "accounts/account", account: account, reconciliation_indicator: reconciliation_indicators[account.id] %>
+ <%= render "accounts/account", account: account %>
<% unless index == accounts.count - 1 %>
<%= render "shared/ruler" %>
<% end %>
diff --git a/app/views/accounts/index/_manual_accounts.html.erb b/app/views/accounts/index/_manual_accounts.html.erb
index 14187735fd..97c08ac07e 100644
--- a/app/views/accounts/index/_manual_accounts.html.erb
+++ b/app/views/accounts/index/_manual_accounts.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (accounts:, reconciliation_indicators: {}) %>
+<%# locals: (accounts:) %>
<details open class="group bg-container p-4 shadow-border-xs rounded-xl">
<summary class="flex items-center gap-2">
@@ -12,6 +12,6 @@
</summary>
<div class="space-y-4 mt-4">
- <%= render "accounts/index/account_groups", accounts: accounts, reconciliation_indicators: reconciliation_indicators %>
+ <%= render "accounts/index/account_groups", accounts: accounts %>
</div>
</details>
diff --git a/app/views/accounts/show/_menu.html.erb b/app/views/accounts/show/_menu.html.erb
index 7a231f5a66..d8d907d07e 100644
--- a/app/views/accounts/show/_menu.html.erb
+++ b/app/views/accounts/show/_menu.html.erb
@@ -1,6 +1,10 @@
<%# locals: (account:) %>
<% permission = account.permission_for(Current.user) %>
+<% bulk_reconciliation = Current.family&.manual_reconciliation? &&
+ account.manual? &&
+ permission.in?([ :owner, :full_control ]) &&
+ account.transactions.exists? %>
<%= render DS::Menu.new(testid: "account-menu") do |menu| %>
<% if permission.in?([ :owner, :full_control ]) %>
<% menu.with_item(variant: "link", text: t(".edit"), href: edit_account_path(account), icon: "pencil-line", data: { turbo_frame: :modal }) %>
@@ -8,6 +12,28 @@
<% menu.with_item(variant: "link", text: t(".sharing"), href: account_sharing_path(account), icon: "users", data: { turbo_frame: :modal }) %>
<% menu.with_item(variant: "link", text: t(".statements"), href: account_path(account, tab: "statements"), icon: "archive") %>
+ <% if bulk_reconciliation %>
+ <% menu.with_item(variant: "divider") %>
+
+ <% Entry.reconciled_statuses.each_key do |status| %>
+ <% status_label = t("transactions.reconcile.statuses.#{status}") %>
+ <% menu.with_item(
+ variant: "button",
+ text: t(".reconcile_all.#{status}"),
+ icon: reconcile_status_icon(status),
+ href: reconcile_all_account_path(account, reconciled_status: status),
+ method: :patch,
+ confirm: CustomConfirm.new(
+ title: t(".reconcile_all.confirm_title", status: status_label),
+ body: t(".reconcile_all.confirm_body"),
+ btn_text: t(".reconcile_all.confirm_accept", status: status_label),
+ destructive: status == "unreconciled"
+ ),
+ data: { turbo_frame: :_top }
+ ) %>
+ <% end %>
+ <% end %>
+
<% if permission.in?([ :owner, :full_control ]) %>
<% menu.with_item(variant: "divider") %>
diff --git a/app/views/entries/_selection_bar.html.erb b/app/views/entries/_selection_bar.html.erb
index ec7868f8d8..e76db329fd 100644
--- a/app/views/entries/_selection_bar.html.erb
+++ b/app/views/entries/_selection_bar.html.erb
@@ -21,12 +21,14 @@
<%= link_to new_transactions_bulk_update_path,
class: "p-1.5 group/edit hover:bg-inverse flex items-center justify-center rounded-md",
title: t("transactions.selection_bar.edit"),
- data: { turbo_frame: "bulk_transaction_edit_drawer" } do %>
+ data: { turbo_frame: "bulk_transaction_edit_drawer", bulk_select_target: "editLink" } do %>
<%= icon "pencil-line", class: "group-hover/edit:text-inverse" %>
<% end %>
+ <%= render "transactions/reconcile_menu", enabled: @account.nil? || @account.manual? %>
+
<%= form_with url: transactions_bulk_deletion_path, data: { turbo_confirm: CustomConfirm.for_resource_deletion("entry").to_data_attribute, turbo_frame: "_top" } do %>
- <button type="button" data-bulk-select-scope-param="bulk_delete" data-action="bulk-select#submitBulkRequest" class="p-1.5 group/delete hover:bg-inverse flex items-center justify-center rounded-md" title="Delete">
+ <button type="button" data-bulk-select-scope-param="bulk_delete" data-bulk-select-target="deleteButton" data-action="bulk-select#submitBulkRequest" class="p-1.5 group/delete hover:bg-inverse flex items-center justify-center rounded-md" title="Delete">
<%= icon "trash-2", class: "group-hover/delete:text-inverse" %>
</button>
<% end %>
diff --git a/app/views/pages/dashboard/_balance_sheet.html.erb b/app/views/pages/dashboard/_balance_sheet.html.erb
index 928dc98f0f..9b88898bff 100644
--- a/app/views/pages/dashboard/_balance_sheet.html.erb
+++ b/app/views/pages/dashboard/_balance_sheet.html.erb
@@ -79,7 +79,7 @@
<% account_group.accounts.each_with_index do |account, idx| %>
<div class="pl-7 pr-4 py-3 flex items-center justify-between text-sm font-medium">
<div class="flex items-center gap-2">
- <%= render "accounts/logo", account: account, size: "sm", color: account_group.color, reconciliation_indicator: @reconciliation_indicators[account.id] %>
+ <%= render "accounts/logo", account: account, size: "sm", color: account_group.color %>
<%= link_to account.name, account_path(account) %>
</div>
diff --git a/app/views/transactions/_reconcile_menu.html.erb b/app/views/transactions/_reconcile_menu.html.erb
new file mode 100644
index 0000000000..707befba20
--- /dev/null
+++ b/app/views/transactions/_reconcile_menu.html.erb
@@ -0,0 +1,25 @@
+<%# locals: (enabled: true) %>
+
+<% if enabled && Current.family&.manual_reconciliation? %>
+ <div data-bulk-select-target="reconcileMenu">
+ <%= render DS::Menu.new(variant: "button") do |menu| %>
+ <% menu.with_button(
+ class: "p-1.5 group/reconcile hover:bg-inverse flex items-center justify-center rounded-md",
+ aria: { label: t("transactions.selection_bar.reconcile") }
+ ) do %>
+ <%= icon "check-circle", class: "group-hover/reconcile:text-inverse" %>
+ <% end %>
+
+ <% Entry.reconciled_statuses.keys.each do |status| %>
+ <% menu.with_item(
+ variant: "button",
+ text: t("transactions.reconcile.statuses.#{status}"),
+ icon: reconcile_status_icon(status),
+ href: transactions_bulk_update_path(bulk_update: { reconciled_status: status }),
+ method: :post,
+ frame: :_top
+ ) %>
+ <% end %>
+ <% end %>
+ </div>
+<% end %>
diff --git a/app/views/transactions/_selection_bar.html.erb b/app/views/transactions/_selection_bar.html.erb
index 34c7f8968d..3c1659ec6f 100644
--- a/app/views/transactions/_selection_bar.html.erb
+++ b/app/views/transactions/_selection_bar.html.erb
@@ -21,37 +21,14 @@
<%= link_to new_transactions_bulk_update_path,
class: "p-1.5 group/edit hover:bg-inverse flex items-center justify-center rounded-md",
title: t("transactions.selection_bar.edit"),
- data: { turbo_frame: "bulk_transaction_edit_drawer" } do %>
+ data: { turbo_frame: "bulk_transaction_edit_drawer", bulk_select_target: "editLink" } do %>
<%= icon "pencil-line", class: "group-hover/edit:text-inverse" %>
<% end %>
- <%# Quick bulk-reconcile — works across accounts in one selection; entries
- belonging to synced (non-manual) accounts are silently skipped
- server-side (see Entry.bulk_update!). %>
- <% if Current.family&.manual_reconciliation? %>
- <%= render DS::Menu.new(variant: "button") do |menu| %>
- <% menu.with_button(
- class: "p-1.5 group/reconcile hover:bg-inverse flex items-center justify-center rounded-md",
- aria: { label: t("transactions.selection_bar.reconcile") }
- ) do %>
- <%= icon "check-circle", class: "group-hover/reconcile:text-inverse" %>
- <% end %>
-
- <% Entry.reconciled_statuses.keys.each do |status| %>
- <% menu.with_item(
- variant: "button",
- text: t("transactions.reconcile.statuses.#{status}"),
- icon: reconcile_status_icon(status),
- href: transactions_bulk_update_path(bulk_update: { reconciled_status: status }),
- method: :post,
- data: { action: "bulk-select#submitBulkRequest", bulk_select_scope_param: "bulk_update" }
- ) %>
- <% end %>
- <% end %>
- <% end %>
+ <%= render "transactions/reconcile_menu" %>
<%= form_with url: transactions_bulk_deletion_path, data: { turbo_confirm: true, turbo_frame: "_top" } do %>
- <button type="button" data-bulk-select-scope-param="bulk_delete" data-action="bulk-select#submitBulkRequest" class="p-1.5 group/delete hover:bg-inverse flex items-center justify-center rounded-md" title="Delete">
+ <button type="button" data-bulk-select-scope-param="bulk_delete" data-bulk-select-target="deleteButton" data-action="bulk-select#submitBulkRequest" class="p-1.5 group/delete hover:bg-inverse flex items-center justify-center rounded-md" title="Delete">
<%= icon "trash-2", class: "group-hover/delete:text-inverse" %>
</button>
<% end %>
diff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erb
index 59f8f48b14..c104b1e55d 100644
--- a/app/views/transactions/_transaction.html.erb
+++ b/app/views/transactions/_transaction.html.erb
@@ -21,11 +21,13 @@
<div class="pr-4 lg:pr-10 flex items-center gap-3 lg:gap-4 col-span-5 min-w-0 max-md:flex-1">
<%= check_box_tag dom_id(entry, "selection"),
- disabled: transaction.transfer.present?,
+ disabled: transaction.transfer.present? && !bulk_reconcilable_transfer?(entry),
class: "checkbox checkbox--light hidden lg:block",
data: {
id: entry.id,
entry_type: entry.entryable_type,
+ transfer: transaction.transfer.present?,
+ category_editable: transaction.category_editable?,
"bulk-select-target": "row",
action: "bulk-select#toggleRowSelection",
checkbox_toggle_target: "selectionEntry"
diff --git a/app/views/transactions/bulk_updates/new.html.erb b/app/views/transactions/bulk_updates/new.html.erb
index a342438acb..69f1f7d851 100644
--- a/app/views/transactions/bulk_updates/new.html.erb
+++ b/app/views/transactions/bulk_updates/new.html.erb
@@ -4,23 +4,32 @@
<% dialog.with_body do %>
<%= styled_form_with url: transactions_bulk_update_path, scope: "bulk_update", class: "h-full flex flex-col justify-between gap-4", data: { turbo_frame: "_top" } do |form| %>
<div class="space-y-4">
- <%= render DS::Disclosure.new(title: t(".overview"), open: true) do %>
- <%= form.date_field :date, label: t(".date_label") %>
+ <% unless @has_transfer_entry %>
+ <%= render DS::Disclosure.new(title: t(".overview"), open: true) do %>
+ <%= form.date_field :date, label: t(".date_label") %>
+ <% end %>
<% end %>
<%= render DS::Disclosure.new(title: t(".transactions_section"), open: true) do %>
<div class="space-y-2">
<%= form.text_field :name, label: t(".name_label"), placeholder: t(".name_placeholder") %>
- <%= form.collection_select :category_id, Current.family.categories.alphabetically_by_hierarchy, :id, :name, { prompt: t(".category_prompt"), label: t(".category_label"), class: "text-subdued", variant: :badge, searchable: true } %>
- <%= form.collection_select :merchant_id, Current.family.available_merchants_for(Current.user).alphabetically, :id, :name, { prompt: t(".merchant_prompt"), label: t(".merchant_label"), class: "text-subdued" } %>
+ <% if @has_category_editable_entry %>
+ <%= form.collection_select :category_id, Current.family.categories.alphabetically_by_hierarchy, :id, :name, { prompt: t(".category_prompt"), label: t(".category_label"), class: "text-subdued", variant: :badge, searchable: true } %>
+ <% end %>
+ <% if @has_normal_transaction_entry %>
+ <%= form.collection_select :merchant_id, Current.family.available_merchants_for(Current.user).alphabetically, :id, :name, { prompt: t(".merchant_prompt"), label: t(".merchant_label"), class: "text-subdued" } %>
+ <% end %>
<%= form.select :tag_ids, Current.family.tags.alphabetically.pluck(:name, :id), { include_blank: t(".none"), multiple: true, label: t(".tags_label"), include_hidden: false } %>
- <% if Current.family&.manual_reconciliation? %>
+ <% if Current.family&.manual_reconciliation? && @has_transaction_entry %>
<%= form.select :reconciled_status,
Entry.reconciled_statuses.keys.map { |status| [ t("transactions.reconcile.statuses.#{status}"), status ] },
{ include_blank: t(".no_change"), label: t(".reconciled_status_label") } %>
<p class="text-xs text-secondary"><%= t(".reconciled_status_hint") %></p>
<% end %>
<%= form.text_area :notes, label: t(".notes_label"), placeholder: t(".notes_placeholder"), rows: 5 %>
+ <% if @has_transfer_entry %>
+ <p class="text-xs text-secondary"><%= t(".transfer_fields_hint") %></p>
+ <% end %>
</div>
<% end %>
</div>
diff --git a/app/views/transactions/searches/filters/_reconcile_status_filter.html.erb b/app/views/transactions/searches/filters/_reconcile_status_filter.html.erb
index 2d2761d9fd..0602d84283 100644
--- a/app/views/transactions/searches/filters/_reconcile_status_filter.html.erb
+++ b/app/views/transactions/searches/filters/_reconcile_status_filter.html.erb
@@ -14,4 +14,6 @@
<%= form.label :reconcile_status, t("transactions.reconcile.statuses.#{status}"), value: status, class: "text-sm text-primary" %>
</div>
<% end %>
+
+ <p class="text-xs text-secondary"><%= t("transactions.search.filters.reconcile_status_hint") %></p>
</div>
diff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.yml
index cc31652b14..3fad1f2e08 100644
--- a/config/locales/views/accounts/en.yml
+++ b/config/locales/views/accounts/en.yml
@@ -9,6 +9,12 @@ en:
matched: All transactions reconciled
needs_attention: Transactions need reconciliation
not_authorized: "You don't have permission to manage this account"
+ reconcile_all:
+ success:
+ one: "%{count} transaction marked as %{status}."
+ other: "%{count} transactions marked as %{status}."
+ invalid_status: "Choose a valid reconciliation status."
+ not_manual_account: "Bulk reconciliation is only available for manually entered accounts."
scheduled_balance_tooltip:
description: Your balance once all scheduled transactions have posted
current: Current balance
@@ -175,6 +181,13 @@ en:
import_trades: Import trades
import_transactions: Import transactions
manage: Manage accounts
+ reconcile_all:
+ cleared: Mark all as cleared
+ confirm_accept: Mark all as %{status}
+ confirm_body: This changes the reconciliation status of every transaction in this account. Uploaded statements stay the same.
+ confirm_title: Mark every transaction as %{status}?
+ reconciled: Mark all as reconciled
+ unreconciled: Mark all as unreconciled
sharing: Sharing
statements: Statements
exclude_from_reports: Exclude from all reports
diff --git a/config/locales/views/transactions/de.yml b/config/locales/views/transactions/de.yml
index bc53521056..6ad8fb4aa8 100644
--- a/config/locales/views/transactions/de.yml
+++ b/config/locales/views/transactions/de.yml
@@ -207,6 +207,7 @@ de:
type: Typ
status: Status
reconcile_status: Abgleich
+ reconcile_status_hint: Nur manuelle Konten werden einbezogen.
amount: Betrag
category: Kategorie
tag: Tag
@@ -357,6 +358,7 @@ de:
overview: Übersicht
reconciled_status_hint: Gilt nur für manuell erfasste Konten (kein Bank-Sync).
reconciled_status_label: Abgleichsstatus
+ transfer_fields_hint: Bei Übertragungen bleiben Datum und Händler unverändert. Die Kategorie gilt nur für Übertragungsabflüsse, die sie zulassen.
save: Speichern
tags_label: Tags
transactions_section: Transaktionen
diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.yml
index 6cb438e120..4297b6e73b 100644
--- a/config/locales/views/transactions/en.yml
+++ b/config/locales/views/transactions/en.yml
@@ -19,6 +19,7 @@ en:
overview: Overview
reconciled_status_hint: Only applies to manually-entered accounts (no bank sync).
reconciled_status_label: Reconciliation status
+ transfer_fields_hint: For transfers, date and merchant stay unchanged. Category applies only to transfer outflows that allow it.
save: Save
tags_label: Tags
transactions_section: Transactions
@@ -301,6 +302,7 @@ en:
type: Type
status: Status
reconcile_status: Reconciliation
+ reconcile_status_hint: Only manual accounts are included.
amount: Amount
category: Category
tag: Tag
diff --git a/config/routes.rb b/config/routes.rb
index 87d31155c2..931b32d652 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -748,6 +748,7 @@ Rails.application.routes.draw do
get :sparkline
patch :toggle_active
patch :toggle_exclude_from_reports
+ patch :reconcile_all
patch :set_default
patch :remove_default
get :select_provider
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index cb90728220..ae5bfe88a1 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -17,18 +17,30 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_select "p.ml-auto.privacy-sensitive"
end
- test "account reconciliation indicators only render when manual reconciliation is enabled" do
- get accounts_url
+ test "account reconciliation indicator renders only on the account page" do
+ create_transaction(account: @account, name: "Unreconciled", amount: 10)
+
+ get account_url(@account)
assert_response :success
assert_not_includes response.body, I18n.t("accounts.reconciliation_indicator.needs_attention")
@user.family.update!(manual_reconciliation: true)
+ get account_url(@account)
+
+ assert_response :success
+ assert_equal 1, response.body.scan(I18n.t("accounts.reconciliation_indicator.needs_attention")).size
+
get accounts_url
assert_response :success
- assert_includes response.body, I18n.t("accounts.reconciliation_indicator.needs_attention")
+ assert_not_includes response.body, I18n.t("accounts.reconciliation_indicator.needs_attention")
+
+ get root_url
+
+ assert_response :success
+ assert_not_includes response.body, I18n.t("accounts.reconciliation_indicator.needs_attention")
end
# Opening the account groups makes the list scroll; reserving the scrollbar's
@@ -616,6 +628,238 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_select "##{dom_id(valuation)}", count: 0
end
+ test "show filters activity by reconciliation status on a manual account" do
+ @user.family.update!(manual_reconciliation: true)
+ cleared = create_transaction(name: "Cleared", amount: 50, account: @account)
+ cleared.update!(reconciled_status: "cleared")
+ unreconciled = create_transaction(name: "Unreconciled", amount: 60, account: @account)
+
+ get account_url(@account), params: { q: { reconcile_status: [ "cleared" ] } }
+
+ assert_response :success
+ assert_select "##{dom_id(cleared)}"
+ assert_select "##{dom_id(unreconciled)}", count: 0
+ assert_select "#transaction-filters-menu button[data-id=?]", "reconcile_status_filter"
+ end
+
+ test "show hides the reconciliation filter on a synced account and drops the param" do
+ @user.family.update!(manual_reconciliation: true)
+ synced_account = accounts(:connected)
+ entry = create_transaction(name: "Synced entry", amount: 50, account: synced_account)
+
+ get account_url(synced_account), params: { q: { reconcile_status: [ "unreconciled" ] } }
+
+ assert_response :success
+ assert_select "#transaction-filters-menu button[data-id=?]", "reconcile_status_filter", count: 0
+ assert_select "##{dom_id(entry)}"
+ end
+
+ test "reconcile_all marks every transaction on a manual account and keeps statement data" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ first = create_transaction(account: account, name: "First", amount: 10)
+ second = create_transaction(account: account, name: "Second", amount: 20)
+ valuation = create_valuation(account: account, date: 2.days.ago.to_date)
+ other_account_entry = create_transaction(account: accounts(:credit_card), name: "Other account")
+ reconciled_at = 2.days.ago.change(usec: 0)
+ first.update_columns(reconciled_at: reconciled_at)
+
+ patch reconcile_all_account_url(account), params: { reconciled_status: "reconciled" }
+
+ assert_redirected_to account_url(account)
+ assert_equal I18n.t("accounts.reconcile_all.success", count: 2, status: I18n.t("transactions.reconcile.statuses.reconciled")), flash[:notice]
+ assert_equal %w[reconciled reconciled], [ first, second ].map { |entry| entry.reload.reconciled_status }
+ assert_equal reconciled_at, first.reload.reconciled_at
+ assert_equal "unreconciled", valuation.reload.reconciled_status
+ assert_equal "unreconciled", other_account_entry.reload.reconciled_status
+ end
+
+ test "reconcile_all rejects a synced account" do
+ @user.family.update!(manual_reconciliation: true)
+ account = accounts(:connected)
+ entry = create_transaction(account: account, name: "Synced")
+
+ patch reconcile_all_account_url(account), params: { reconciled_status: "reconciled" }
+
+ assert_redirected_to account_url(account)
+ assert_equal I18n.t("accounts.reconcile_all.not_manual_account"), flash[:alert]
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "reconcile_all rejects an unknown status" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ entry = create_transaction(account: account, name: "Untouched")
+
+ patch reconcile_all_account_url(account), params: { reconciled_status: "bogus" }
+
+ assert_redirected_to account_url(account)
+ assert_equal I18n.t("accounts.reconcile_all.invalid_status"), flash[:alert]
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "reconcile_all returns not found when manual reconciliation is disabled" do
+ account = create_manual_account
+ entry = create_transaction(account: account, name: "Untouched")
+
+ patch reconcile_all_account_url(account), params: { reconciled_status: "reconciled" }
+
+ assert_response :not_found
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "reconcile_all requires write permission" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ entry = create_transaction(account: account, name: "Untouched")
+ member = users(:family_member)
+ account.account_shares.create!(user: member, permission: "read_only")
+
+ sign_in member
+ patch reconcile_all_account_url(account), params: { reconciled_status: "reconciled" }
+
+ assert_redirected_to account_url(account)
+ assert_equal I18n.t("accounts.not_authorized"), flash[:alert]
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "show offers bulk reconciliation only on an eligible manual account" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ create_transaction(account: account, name: "Transaction")
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "[data-testid='account-menu']" do
+ assert_select "button", text: /#{I18n.t("accounts.show.menu.reconcile_all.unreconciled")}/
+ assert_select "button", text: /#{I18n.t("accounts.show.menu.reconcile_all.cleared")}/
+ assert_select "button", text: /#{I18n.t("accounts.show.menu.reconcile_all.reconciled")}/
+ end
+ assert_select "form[action=?]", reconcile_all_account_path(account, reconciled_status: "reconciled")
+ end
+
+ test "show hides bulk reconciliation without the family setting" do
+ account = create_manual_account
+ create_transaction(account: account, name: "Transaction")
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "form[action=?]", reconcile_all_account_path(account, reconciled_status: "reconciled"), count: 0
+ end
+
+ test "show hides bulk reconciliation on a synced account" do
+ @user.family.update!(manual_reconciliation: true)
+ account = accounts(:connected)
+ create_transaction(account: account, name: "Synced")
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "form[action=?]", reconcile_all_account_path(account, reconciled_status: "reconciled"), count: 0
+ end
+
+ test "show hides bulk reconciliation on an account without transactions" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "form[action=?]", reconcile_all_account_path(account, reconciled_status: "reconciled"), count: 0
+ end
+
+ test "show hides bulk reconciliation from a read-only share" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ create_transaction(account: account, name: "Transaction")
+ member = users(:family_member)
+ account.account_shares.create!(user: member, permission: "read_only")
+
+ sign_in member
+ get account_url(account)
+
+ assert_response :success
+ assert_select "form[action=?]", reconcile_all_account_path(account, reconciled_status: "reconciled"), count: 0
+ end
+
+ test "reconcile_all allows a member with full_control" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ entry = create_transaction(account: account, name: "Shared")
+ member = users(:family_member)
+ account.account_shares.create!(user: member, permission: "full_control")
+
+ sign_in member
+ patch reconcile_all_account_url(account), params: { reconciled_status: "cleared" }
+
+ assert_redirected_to account_url(account)
+ assert_equal "cleared", entry.reload.reconciled_status
+ end
+
+ test "reconcile_all treats a missing status as invalid" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ entry = create_transaction(account: account, name: "Untouched")
+
+ patch reconcile_all_account_url(account)
+
+ assert_redirected_to account_url(account)
+ assert_equal I18n.t("accounts.reconcile_all.invalid_status"), flash[:alert]
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "reconcile_all reports zero updates for an account without transactions" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+
+ patch reconcile_all_account_url(account), params: { reconciled_status: "cleared" }
+
+ assert_redirected_to account_url(account)
+ assert_equal I18n.t("accounts.reconcile_all.success", count: 0, status: I18n.t("transactions.reconcile.statuses.cleared")), flash[:notice]
+ end
+
+ test "reconcile_all does not reach an account in another family" do
+ @user.family.update!(manual_reconciliation: true)
+ other_account = Account.create!(
+ family: families(:inactive_trial),
+ name: "Someone else's account",
+ balance: 0,
+ currency: "USD",
+ accountable: Depository.new
+ )
+
+ patch reconcile_all_account_url(other_account), params: { reconciled_status: "reconciled" }
+
+ assert_response :not_found
+ end
+
+ test "show hides bulk reconciliation on an account with only valuations" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ create_valuation(account: account, date: 2.days.ago.to_date)
+
+ get account_url(account)
+
+ assert_response :success
+ assert_select "form[action=?]", reconcile_all_account_path(account, reconciled_status: "reconciled"), count: 0
+ end
+
+ test "the bulk reconciliation items carry a confirmation" do
+ @user.family.update!(manual_reconciliation: true)
+ account = create_manual_account
+ create_transaction(account: account, name: "Transaction")
+
+ get account_url(account)
+
+ assert_response :success
+ Entry.reconciled_statuses.each_key do |status|
+ assert_select "form[action=?] button[data-turbo-confirm]",
+ reconcile_all_account_path(account, reconciled_status: status)
+ end
+ end
+
test "show hides balance updates on a linked account by default" do
account = accounts(:connected)
transaction = create_transaction(account: account, name: "Linked Transaction")
@@ -2029,6 +2273,16 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
end
private
+ # A manual (unsynced) account with no entries, so counts stay exact.
+ def create_manual_account
+ @user.family.accounts.create!(
+ name: "Manual test account",
+ balance: 100,
+ currency: "USD",
+ accountable: Depository.new
+ )
+ end
+
def sidebar_sparkline_src(frame_id)
css_select("turbo-frame##{frame_id}").first["src"]
end
diff --git a/test/controllers/transactions/bulk_updates_controller_test.rb b/test/controllers/transactions/bulk_updates_controller_test.rb
index abc73abe74..0da4452149 100644
--- a/test/controllers/transactions/bulk_updates_controller_test.rb
+++ b/test/controllers/transactions/bulk_updates_controller_test.rb
@@ -8,7 +8,8 @@ class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
end
test "bulk update" do
- transactions = @user.family.entries.transactions
+ transfer_entry_ids = [ entries(:transfer_out).id, entries(:transfer_in).id ]
+ transactions = @user.family.entries.transactions.where.not(id: transfer_entry_ids)
assert_difference [ "Entry.count", "Transaction.count" ], 0 do
post transactions_bulk_update_url, params: {
@@ -35,6 +36,328 @@ class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
end
end
+ test "bulk update keeps transfer date, category and merchant" do
+ @user.family.update!(manual_reconciliation: true)
+ transfer = create_transfer(
+ from_account: accounts(:depository),
+ to_account: accounts(:credit_card),
+ amount: 100,
+ date: Date.current
+ )
+ outflow_entry = transfer.outflow_transaction.entry
+ inflow_entry = transfer.inflow_transaction.entry
+ original_date = outflow_entry.date
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ outflow_entry.id ],
+ date: 1.day.ago.to_date,
+ category_id: Category.second.id,
+ merchant_id: Merchant.second.id,
+ tag_ids: [ Tag.first.id ],
+ notes: "Transfer note",
+ reconciled_status: "reconciled"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ outflow_entry.reload
+ assert_equal original_date, outflow_entry.date
+ assert_nil outflow_entry.transaction.category_id
+ assert_nil outflow_entry.transaction.merchant_id
+ assert_equal "Transfer note", outflow_entry.notes
+ assert_equal [ Tag.first.id ], outflow_entry.transaction.tag_ids
+ assert_equal "reconciled", outflow_entry.reconciled_status
+
+ inflow_entry.reload
+ assert_equal original_date, inflow_entry.date
+ assert_nil inflow_entry.transaction.category_id
+ assert_equal "unreconciled", inflow_entry.reconciled_status
+ end
+
+ test "bulk update applies a category to a categorizable transfer outflow" do
+ transfer = create_transfer(
+ from_account: accounts(:depository),
+ to_account: accounts(:investment),
+ amount: 100
+ )
+ outflow_entry = transfer.outflow_transaction.entry
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ outflow_entry.id ],
+ category_id: Category.second.id
+ }
+ }
+
+ assert_redirected_to transactions_url
+ assert_equal Category.second.id, outflow_entry.reload.transaction.category_id
+ end
+
+ test "bulk update keeps an unmatched transfer-kind transaction editable" do
+ entry = create_transaction(
+ account: accounts(:depository),
+ kind: "funds_movement",
+ name: "Unmatched transfer"
+ )
+ original_date = entry.date
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ entry.id ],
+ date: 1.day.ago.to_date,
+ category_id: Category.second.id,
+ merchant_id: Merchant.second.id,
+ tag_ids: [ Tag.first.id ],
+ notes: "Edited unmatched transfer"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ entry.reload
+ assert_not_equal original_date, entry.date
+ assert_equal 1.day.ago.to_date, entry.date
+ assert_equal Category.second, entry.transaction.category
+ assert_equal Merchant.second, entry.transaction.merchant
+ assert_equal "Edited unmatched transfer", entry.notes
+ assert_equal [ Tag.first.id ], entry.transaction.tag_ids
+ end
+
+ test "bulk update keeps transfer fee transactions editable" do
+ transfer = create_transfer(
+ from_account: accounts(:depository),
+ to_account: accounts(:credit_card),
+ amount: 100
+ )
+ fee_entry = accounts(:depository).entries.create!(
+ name: "Transfer fee",
+ date: Date.current,
+ amount: 10,
+ currency: "USD",
+ entryable: Transaction.new(kind: "standard", transfer: transfer)
+ )
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ fee_entry.id ],
+ date: 1.day.ago.to_date,
+ category_id: Category.second.id,
+ merchant_id: Merchant.second.id,
+ tag_ids: [ Tag.first.id ],
+ notes: "Edited fee"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ fee_entry.reload
+ assert_equal 1.day.ago.to_date, fee_entry.date
+ assert_equal Category.second, fee_entry.transaction.category
+ assert_equal Merchant.second, fee_entry.transaction.merchant
+ assert_equal "Edited fee", fee_entry.notes
+ assert_equal [ Tag.first.id ], fee_entry.transaction.tag_ids
+ end
+
+ test "bulk update applies safe fields to both selected transfer legs" do
+ @user.family.update!(manual_reconciliation: true)
+ transfer = create_transfer(
+ from_account: accounts(:depository),
+ to_account: accounts(:credit_card),
+ amount: 100
+ )
+ outflow_entry = transfer.outflow_transaction.entry
+ inflow_entry = transfer.inflow_transaction.entry
+ original_date = outflow_entry.date
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ outflow_entry.id, inflow_entry.id ],
+ date: 1.day.ago.to_date,
+ category_id: Category.second.id,
+ merchant_id: Merchant.second.id,
+ tag_ids: [ Tag.first.id ],
+ notes: "Both legs",
+ reconciled_status: "reconciled"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ assert_equal "2 transactions updated", flash[:notice]
+
+ [ outflow_entry, inflow_entry ].each do |entry|
+ entry.reload
+ assert_equal original_date, entry.date
+ assert_nil entry.transaction.category_id
+ assert_nil entry.transaction.merchant_id
+ assert_equal "Both legs", entry.notes
+ assert_equal [ Tag.first.id ], entry.transaction.tag_ids
+ assert_equal "reconciled", entry.reconciled_status
+ end
+ end
+
+ test "bulk update applies normal fields to normal entries and safe fields to a transfer" do
+ @user.family.update!(manual_reconciliation: true)
+ normal_entry = create_transaction(account: accounts(:depository), name: "Normal entry")
+ transfer = create_transfer(
+ from_account: accounts(:depository),
+ to_account: accounts(:credit_card),
+ amount: 100
+ )
+ outflow_entry = transfer.outflow_transaction.entry
+ transfer_date = outflow_entry.date
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ normal_entry.id, outflow_entry.id ],
+ date: 1.day.ago.to_date,
+ category_id: Category.second.id,
+ merchant_id: Merchant.second.id,
+ tag_ids: [ Tag.first.id ],
+ notes: "Mixed update",
+ reconciled_status: "reconciled"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ assert_equal "2 transactions updated", flash[:notice]
+
+ normal_entry.reload
+ assert_equal 1.day.ago.to_date, normal_entry.date
+ assert_equal Category.second, normal_entry.transaction.category
+ assert_equal Merchant.second, normal_entry.transaction.merchant
+ assert_equal "Mixed update", normal_entry.notes
+ assert_equal [ Tag.first.id ], normal_entry.transaction.tag_ids
+ assert_equal "reconciled", normal_entry.reconciled_status
+
+ outflow_entry.reload
+ assert_equal transfer_date, outflow_entry.date
+ assert_nil outflow_entry.transaction.category_id
+ assert_nil outflow_entry.transaction.merchant_id
+ assert_equal "Mixed update", outflow_entry.notes
+ assert_equal [ Tag.first.id ], outflow_entry.transaction.tag_ids
+ assert_equal "reconciled", outflow_entry.reconciled_status
+ end
+
+ test "bulk update ignores entries from inaccessible accounts" do
+ entry = create_transaction(account: accounts(:investment), name: "Private entry")
+ entry.update!(notes: "Original note")
+
+ sign_in users(:family_member)
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ entry.id ],
+ notes: "Should not apply"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ assert_equal "0 transactions updated", flash[:notice]
+ assert_equal "Original note", entry.reload.notes
+ end
+
+ test "bulk update does not look up transfers per normal entry" do
+ transfer_entry_ids = [ entries(:transfer_out).id, entries(:transfer_in).id ]
+ transaction_ids = @user.family.entries.transactions
+ .where.not(id: transfer_entry_ids)
+ .limit(5)
+ .pluck(:id)
+
+ queries = capture_sql_queries do
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: transaction_ids,
+ date: 1.day.ago.to_date,
+ category_id: Category.second.id
+ }
+ }
+ end
+
+ transfer_queries = queries.grep(/FROM "?transfers"?/)
+ assert_equal 1, transfer_queries.size,
+ "expected one transfer-leg lookup, got: #{transfer_queries.inspect}"
+ end
+
+ test "new hides the reconciliation field when the selection has no transaction" do
+ @user.family.update!(manual_reconciliation: true)
+
+ get new_transactions_bulk_update_url, params: {
+ has_transaction_entry: "false",
+ has_transfer_entry: "false",
+ has_category_editable_entry: "false",
+ has_normal_transaction_entry: "false"
+ }
+
+ assert_response :success
+ assert_select "select[name='bulk_update[reconciled_status]']", count: 0
+ assert_select "input[name='bulk_update[date]']"
+ assert_select "input[name='bulk_update[category_id]']", count: 0
+ assert_select "input[name='bulk_update[merchant_id]']", count: 0
+ end
+
+ test "new hides transfer-unsafe fields for a non-categorizable transfer" do
+ @user.family.update!(manual_reconciliation: true)
+
+ get new_transactions_bulk_update_url, params: {
+ has_transaction_entry: "true",
+ has_transfer_entry: "true",
+ has_category_editable_entry: "false",
+ has_normal_transaction_entry: "false"
+ }
+
+ assert_response :success
+ assert_select "select[name='bulk_update[reconciled_status]']"
+ assert_select "input[name='bulk_update[date]']", count: 0
+ assert_select "input[name='bulk_update[category_id]']", count: 0
+ assert_select "input[name='bulk_update[merchant_id]']", count: 0
+ assert_select "input[name='bulk_update[name]']"
+ assert_select "textarea[name='bulk_update[notes]']"
+ end
+
+ test "new keeps category for a categorizable transfer outflow" do
+ @user.family.update!(manual_reconciliation: true)
+
+ get new_transactions_bulk_update_url, params: {
+ has_transaction_entry: "true",
+ has_transfer_entry: "true",
+ has_category_editable_entry: "true",
+ has_normal_transaction_entry: "false"
+ }
+
+ assert_response :success
+ assert_select "select[name='bulk_update[reconciled_status]']"
+ assert_select "input[name='bulk_update[date]']", count: 0
+ assert_select "input[name='bulk_update[category_id]']"
+ assert_select "input[name='bulk_update[merchant_id]']", count: 0
+ end
+
+ test "new keeps category and merchant for a mixed selection" do
+ @user.family.update!(manual_reconciliation: true)
+
+ get new_transactions_bulk_update_url, params: {
+ has_transaction_entry: "true",
+ has_transfer_entry: "true",
+ has_category_editable_entry: "true",
+ has_normal_transaction_entry: "true"
+ }
+
+ assert_response :success
+ assert_select "select[name='bulk_update[reconciled_status]']"
+ assert_select "input[name='bulk_update[date]']", count: 0
+ assert_select "input[name='bulk_update[category_id]']"
+ assert_select "input[name='bulk_update[merchant_id]']"
+ end
+
+ test "new shows all fields by default" do
+ @user.family.update!(manual_reconciliation: true)
+
+ get new_transactions_bulk_update_url
+
+ assert_response :success
+ assert_select "select[name='bulk_update[reconciled_status]']"
+ assert_select "input[name='bulk_update[date]']"
+ assert_select "input[name='bulk_update[category_id]']"
+ end
+
test "bulk update preloads transaction records" do
transaction_ids = @user.family.entries.transactions.limit(4).pluck(:id)
@@ -271,6 +594,48 @@ class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
assert_equal [ "Private", nil ], [ private_entry.reload.name, private_entry.notes ]
end
+ test "bulk update locks the whole mixed selection before it writes" do
+ accounts(:credit_card).account_shares.find_by!(user: users(:family_member)).update!(permission: "read_write")
+ full_entry = create_transaction(account: accounts(:depository), name: "Full")
+ annotate_entry = create_transaction(account: accounts(:credit_card), name: "Annotate")
+
+ payloads = []
+ callback = ->(_name, _started, _finished, _unique_id, payload) { payloads << payload }
+
+ sign_in users(:family_member)
+ ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
+ post transactions_bulk_update_url, params: {
+ bulk_update: { entry_ids: [ full_entry.id, annotate_entry.id ], notes: "bulk note" }
+ }
+ end
+
+ assert_equal "2 transactions updated", flash[:notice]
+
+ transaction_lock_index = payloads.index do |payload|
+ payload[:sql].include?("FOR UPDATE") && payload[:sql].include?('"transactions"')
+ end
+ entry_lock_indexes = payloads.each_index.select do |index|
+ payloads[index][:sql].include?("FOR UPDATE") && payloads[index][:sql].include?('"entries"')
+ end
+ first_update_index = payloads.index { |payload| payload[:sql].start_with?('UPDATE "entries"') }
+
+ assert transaction_lock_index, "expected a lock on the transactions"
+ assert entry_lock_indexes.any?, "expected a lock on the entries"
+ assert first_update_index, "expected an entry update"
+
+ first_entry_lock = payloads[entry_lock_indexes.first]
+ locked_ids = first_entry_lock[:binds].flat_map { |bind| Array(bind.value) }
+ assert_includes locked_ids, full_entry.id,
+ "the first entry lock must cover the full-control entry"
+ assert_includes locked_ids, annotate_entry.id,
+ "the first entry lock must cover the annotate-only entry"
+
+ assert_operator transaction_lock_index, :<, entry_lock_indexes.first,
+ "the transactions must be locked before the entries"
+ assert_operator entry_lock_indexes.first, :<, first_update_index,
+ "the whole selection must be locked before the first write"
+ end
+
test "bulk update sets reconciled_status on manual accounts" do
@user.family.update!(manual_reconciliation: true)
manual_entry = create_transaction(account: accounts(:depository))
@@ -287,6 +652,21 @@ class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
assert_equal "reconciled", manual_entry.reload.reconciled_status
end
+ test "bulk update ignores reconciled_status on a valuation" do
+ @user.family.update!(manual_reconciliation: true)
+ valuation = create_valuation(account: accounts(:depository))
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ valuation.id ],
+ reconciled_status: "reconciled"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ assert_equal "unreconciled", valuation.reload.reconciled_status
+ end
+
test "bulk update ignores reconciled_status on synced accounts" do
@user.family.update!(manual_reconciliation: true)
synced_entry = create_transaction(account: accounts(:connected))
diff --git a/test/helpers/transactions_helper_test.rb b/test/helpers/transactions_helper_test.rb
index e9c038fb21..7d0239f831 100644
--- a/test/helpers/transactions_helper_test.rb
+++ b/test/helpers/transactions_helper_test.rb
@@ -2,6 +2,8 @@ require "test_helper"
require "ostruct"
class TransactionsHelperTest < ActionView::TestCase
+ include EntriesTestHelper
+
# build_transaction_extra_details reads `extra` off a Transaction (or anything
# that responds to :transaction), so a struct is enough to drive it.
def transaction_with(extra)
@@ -45,6 +47,74 @@ class TransactionsHelperTest < ActionView::TestCase
"read_write is annotate access, and #reconcile requires write"
end
+ test "reconcile filter is hidden when the user has no accessible manual account" do
+ Current.session = Session.create!(user: users(:empty))
+ Current.family.update!(manual_reconciliation: true)
+
+ assert_not_includes transaction_search_filters.map { |filter| filter[:key] }, "reconcile_status_filter"
+ end
+
+ test "bulk_reconcilable_transfer? is false while the setting is off" do
+ Current.session = Session.create!(user: users(:family_admin))
+
+ assert_not bulk_reconcilable_transfer?(entries(:transfer_out))
+ end
+
+ test "bulk_reconcilable_transfer? is true for a writable manual transfer" do
+ Current.session = Session.create!(user: users(:family_admin))
+ Current.family.update!(manual_reconciliation: true)
+
+ assert bulk_reconcilable_transfer?(entries(:transfer_out))
+ end
+
+ test "bulk_reconcilable_transfer? is false for a read_write share" do
+ share = account_shares(:credit_card_shared_with_member)
+ share.update!(permission: "read_write")
+ Current.session = Session.create!(user: users(:family_member))
+ Current.family.update!(manual_reconciliation: true)
+
+ assert_not bulk_reconcilable_transfer?(entries(:transfer_in))
+ end
+
+ test "bulk_reconcilable_transfer? is false for a synced account" do
+ Current.session = Session.create!(user: users(:family_admin))
+ Current.family.update!(manual_reconciliation: true)
+ transfer = create_transfer(
+ from_account: accounts(:connected),
+ to_account: accounts(:depository),
+ amount: 100
+ )
+
+ assert_not bulk_reconcilable_transfer?(transfer.outflow_transaction.entry)
+ end
+
+ test "bulk_reconcilable_transfer? is false for an unmatched transfer-kind transaction" do
+ Current.session = Session.create!(user: users(:family_admin))
+ Current.family.update!(manual_reconciliation: true)
+ entry = create_transaction(account: accounts(:depository), kind: "funds_movement")
+
+ assert_not bulk_reconcilable_transfer?(entry)
+ end
+
+ test "bulk_reconcilable_transfer? is false for a transfer fee" do
+ Current.session = Session.create!(user: users(:family_admin))
+ Current.family.update!(manual_reconciliation: true)
+ transfer = create_transfer(
+ from_account: accounts(:depository),
+ to_account: accounts(:credit_card),
+ amount: 100
+ )
+ fee_entry = accounts(:depository).entries.create!(
+ name: "Transfer fee",
+ date: Date.current,
+ amount: 10,
+ currency: "USD",
+ entryable: Transaction.new(kind: "standard", transfer: transfer)
+ )
+
+ assert_not bulk_reconcilable_transfer?(fee_entry)
+ end
+
test "extracts the named Plaid fields into their own section" do
details = build_transaction_extra_details(transaction_with({
"plaid" => {
diff --git a/test/models/entry_search_test.rb b/test/models/entry_search_test.rb
index cd98ed9107..3a3e498fe1 100644
--- a/test/models/entry_search_test.rb
+++ b/test/models/entry_search_test.rb
@@ -122,7 +122,71 @@ class EntrySearchTest < ActiveSupport::TestCase
assert_includes result_ids, txn.id
end
- test "family is not required unless a category filter is used" do
+ test "reconcile status filter matches only manual-account transaction entries" do
+ cleared = create_transaction(account: @account, amount: 100)
+ cleared.update!(reconciled_status: "cleared")
+ unreconciled = create_transaction(account: @account, amount: 100)
+ reconciled = create_transaction(account: @account, amount: 100)
+ reconciled.update!(reconciled_status: "reconciled")
+ valuation = create_valuation(account: @account)
+
+ result_ids = @account.entries.search({ reconcile_status: [ "cleared" ] }, @family).pluck(:id)
+
+ assert_includes result_ids, cleared.id
+ assert_not_includes result_ids, unreconciled.id
+ assert_not_includes result_ids, reconciled.id
+ assert_not_includes result_ids, valuation.id
+
+ both_ids = @account.entries.search({ reconcile_status: [ "cleared", "reconciled" ] }, @family).pluck(:id)
+
+ assert_includes both_ids, cleared.id
+ assert_includes both_ids, reconciled.id
+ assert_not_includes both_ids, unreconciled.id
+ end
+
+ test "reconcile status filter is a no-op for blank values" do
+ txn = create_transaction(account: @account, amount: 100)
+ valuation = create_valuation(account: @account)
+
+ result_ids = @account.entries.search({ reconcile_status: [ "" ] }, @family).pluck(:id)
+
+ assert_includes result_ids, txn.id
+ assert_includes result_ids, valuation.id
+ end
+
+ test "reconcile status filter excludes synced accounts" do
+ synced_account = accounts(:connected)
+ entry = create_transaction(account: synced_account, amount: 100)
+ assert_equal "unreconciled", entry.reconciled_status
+
+ result_ids = synced_account.entries.search({ reconcile_status: [ "unreconciled" ] }, @family).pluck(:id)
+
+ assert_empty result_ids
+ end
+
+ test "reconcile status filter includes a reconciled transfer leg in a manual account" do
+ transfer = create_transfer(
+ from_account: @account,
+ to_account: accounts(:credit_card),
+ amount: 100
+ )
+ outflow_entry = transfer.outflow_transaction.entry
+ outflow_entry.update!(reconciled_status: "reconciled")
+
+ result_ids = @account.entries.search({ reconcile_status: [ "reconciled" ] }, @family).pluck(:id)
+
+ assert_includes result_ids, outflow_entry.id
+ end
+
+ test "reconcile status filter requires a family" do
+ create_transaction(account: @account, amount: 100)
+
+ assert_raises ArgumentError do
+ @account.entries.search({ reconcile_status: [ "unreconciled" ] }).pluck(:id)
+ end
+ end
+
+ test "family is not required for merchant-only filters" do
txn = create_transaction(account: @account, amount: 100, merchant: merchants(:netflix))
result_ids = @account.entries.search({ merchants: [ merchants(:netflix).name ] }).pluck(:id)
diff --git a/test/models/entry_test.rb b/test/models/entry_test.rb
index 8176e1cc1d..5d0ba91fdc 100644
--- a/test/models/entry_test.rb
+++ b/test/models/entry_test.rb
@@ -128,6 +128,116 @@ class EntryTest < ActiveSupport::TestCase
assert_equal "unreconciled", entry.reload.reconciled_status
end
+ test "set_reconciled_status_for_account! updates every transaction on the account" do
+ account = Account.create!(
+ family: families(:dylan_family),
+ name: "Bulk reconcile",
+ balance: 0,
+ currency: "USD",
+ accountable: Depository.new
+ )
+ cleared = create_transaction(account: account, name: "Cleared")
+ reconciled = create_transaction(account: account, name: "Reconciled")
+ excluded = create_transaction(account: account, name: "Excluded")
+ cleared.update!(reconciled_status: "cleared")
+ reconciled.update!(reconciled_status: "reconciled")
+ excluded.update!(excluded: true)
+
+ updated_count = Entry.set_reconciled_status_for_account!(account, "reconciled")
+
+ assert_equal 3, updated_count
+ assert_equal %w[reconciled reconciled reconciled], [ cleared, reconciled, excluded ].map { |entry| entry.reload.reconciled_status }
+ assert_not cleared.reload.user_modified?, "reconciling is not an edit, so the entry stays open to auto-categorization"
+ end
+
+ test "set_reconciled_status_for_account! accepts every reconciled status" do
+ account = accounts(:depository)
+ entry = create_transaction(account: account, name: "Cycles")
+
+ Entry.reconciled_statuses.each_key do |status|
+ Entry.set_reconciled_status_for_account!(account, status)
+ assert_equal status, entry.reload.reconciled_status
+ end
+ end
+
+ test "set_reconciled_status_for_account! returns zero when the account has no transactions" do
+ account = Account.create!(
+ family: families(:dylan_family),
+ name: "Valuations only",
+ balance: 0,
+ currency: "USD",
+ accountable: Depository.new
+ )
+ create_valuation(account: account, date: 2.days.ago.to_date)
+
+ assert_equal 0, Entry.set_reconciled_status_for_account!(account, "reconciled")
+ end
+
+ test "set_reconciled_status_for_account! leaves other accounts, valuations and statement data alone" do
+ account = accounts(:depository)
+ entry = create_transaction(account: account, name: "Manual entry")
+ valuation = create_valuation(account: account, date: 2.days.ago.to_date)
+ other_entry = create_transaction(account: accounts(:credit_card), name: "Other account")
+ reconciled_at = 3.days.ago.change(usec: 0)
+ entry.update_columns(reconciled_at: reconciled_at, reconciled_by_statement_id: nil)
+
+ Entry.set_reconciled_status_for_account!(account, "cleared")
+
+ assert_equal "cleared", entry.reload.reconciled_status
+ assert_equal reconciled_at, entry.reconciled_at
+ assert_equal "unreconciled", valuation.reload.reconciled_status
+ assert_equal "unreconciled", other_entry.reload.reconciled_status
+ end
+
+ test "set_reconciled_status_for_account! updates split children but not the split parent" do
+ account = accounts(:depository)
+ parent = create_transaction(account: account, name: "Split parent", amount: 100)
+ parent.split!([ { name: "Part 1", amount: 60 }, { name: "Part 2", amount: 40 } ])
+ parent.reload
+
+ Entry.set_reconciled_status_for_account!(account, "cleared")
+
+ assert_equal "unreconciled", parent.reconciled_status, "the activity list hides split parents, so their status stays untouched"
+ assert_equal %w[cleared cleared], parent.child_entries.map { |child| child.reload.reconciled_status }
+ end
+
+ test "set_reconciled_status_for_account! changes the row cache key" do
+ account = accounts(:depository)
+ entry = create_transaction(account: account, name: "Cached row")
+ entry.update_columns(updated_at: 1.day.ago)
+ old_key = entry.reload.cache_key_with_version
+
+ Entry.set_reconciled_status_for_account!(account, "reconciled")
+
+ assert_not_equal old_key, entry.reload.cache_key_with_version
+ end
+
+ test "set_reconciled_status_for_account! locks entries by id before updating them" do
+ account = accounts(:depository)
+ create_transaction(account: account, name: "Locked row")
+
+ payloads = []
+ callback = ->(_name, _started, _finished, _unique_id, payload) { payloads << payload }
+
+ ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
+ Entry.set_reconciled_status_for_account!(account, "cleared")
+ end
+
+ lock_index = payloads.index { |payload| payload[:sql].include?("FOR UPDATE OF entries") }
+ update_index = payloads.index { |payload| payload[:sql].start_with?('UPDATE "entries"') }
+
+ assert lock_index, "expected an entry lock"
+ assert update_index, "expected the entry update"
+ assert_operator lock_index, :<, update_index, "the entries must be locked before the update"
+ assert_match(/ORDER BY "entries"\."id" ASC/, payloads[lock_index][:sql])
+ end
+
+ test "set_reconciled_status_for_account! rejects an unknown status" do
+ assert_raises(ArgumentError) do
+ Entry.set_reconciled_status_for_account!(accounts(:depository), "bogus")
+ end
+ end
+
test "bulk_update! applies reconciled_status only to manual entries in a mixed selection and reports the accurate count" do
manual_entry = create_transaction(account: accounts(:depository))
synced_entry = create_transaction(account: accounts(:connected))
diff --git a/test/system/account_activity_test.rb b/test/system/account_activity_test.rb
index 4265d3386e..b3e3c8e390 100644
--- a/test/system/account_activity_test.rb
+++ b/test/system/account_activity_test.rb
@@ -1,6 +1,8 @@
require "application_system_test_case"
class AccountActivityTest < ApplicationSystemTestCase
+ include EntriesTestHelper
+
DEFAULT_VIEWPORT_WIDTH = 1400
DEFAULT_VIEWPORT_HEIGHT = 1400
@@ -46,6 +48,151 @@ class AccountActivityTest < ApplicationSystemTestCase
end
end
+ test "account activity keeps edit for a transfer and hides delete and duplicate" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+ transfer = create_transfer(from_account: @account, to_account: accounts(:credit_card), amount: 100)
+ outflow_entry = transfer.outflow_transaction.entry
+
+ visit account_url(@account, tab: "activity")
+
+ find("##{dom_id(outflow_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ assert_selector "a[title='Edit']"
+ assert_selector "a[title='Duplicate'].hidden", visible: false
+ assert_selector "button[title='Delete'].hidden", visible: false
+ assert_selector "button[aria-label='#{I18n.t("transactions.selection_bar.reconcile")}']"
+ end
+ end
+
+ test "account activity reconciles a transfer leg through the edit drawer" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+ transfer = create_transfer(from_account: @account, to_account: accounts(:credit_card), amount: 100)
+ outflow_entry = transfer.outflow_transaction.entry
+ inflow_entry = transfer.inflow_transaction.entry
+
+ visit account_url(@account, tab: "activity")
+
+ find("##{dom_id(outflow_entry, "selection")}").check
+ within "#entry-selection-bar" do
+ find("a[title='Edit']").click
+ end
+
+ within "#bulk_transaction_edit_drawer" do
+ assert_selector "input[name='bulk_update[name]']"
+ end
+
+ assert_no_selector "input[name='bulk_update[date]']"
+ assert_no_selector "input[name='bulk_update[category_id]']", visible: :all
+ assert_no_selector "input[name='bulk_update[merchant_id]']", visible: :all
+
+ select I18n.t("transactions.reconcile.statuses.reconciled"), from: "bulk_update_reconciled_status"
+ click_button I18n.t("transactions.bulk_updates.new.save")
+
+ assert_selector "##{dom_id(outflow_entry)} a[aria-label='#{I18n.t("transactions.reconcile.statuses.reconciled")}']"
+ assert_equal "unreconciled", inflow_entry.reload.reconciled_status
+ end
+
+ test "account activity reconciles a transfer leg with the quick action" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+ transfer = create_transfer(from_account: @account, to_account: accounts(:credit_card), amount: 100)
+ outflow_entry = transfer.outflow_transaction.entry
+ inflow_entry = transfer.inflow_transaction.entry
+
+ visit account_url(@account, tab: "activity")
+
+ find("##{dom_id(outflow_entry, "selection")}").check
+ within "#entry-selection-bar" do
+ find("button[aria-label='#{I18n.t("transactions.selection_bar.reconcile")}']").click
+ end
+ click_button I18n.t("transactions.reconcile.statuses.reconciled")
+
+ assert_selector "##{dom_id(outflow_entry)} a[aria-label='#{I18n.t("transactions.reconcile.statuses.reconciled")}']"
+ assert_equal "unreconciled", inflow_entry.reload.reconciled_status
+ end
+
+ test "account activity hides reconcile when only a valuation is selected" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+
+ visit account_url(@account, tab: "activity")
+
+ find("##{dom_id(@valuation_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ assert_selector "[data-bulk-select-target='reconcileMenu'].hidden", visible: false
+ assert_selector "a[title='Edit']"
+ assert_selector "button[title='Delete']"
+ end
+ end
+
+ test "account activity hides reconciliation in the edit drawer for a valuation" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+
+ visit account_url(@account, tab: "activity")
+
+ find("##{dom_id(@valuation_entry, "selection")}").check
+ within "#entry-selection-bar" do
+ find("a[title='Edit']").click
+ end
+
+ within "#bulk_transaction_edit_drawer" do
+ assert_selector "input[name='bulk_update[name]']"
+ end
+
+ assert_no_selector "select[name='bulk_update[reconciled_status]']"
+ assert_selector "input[name='bulk_update[date]']"
+ end
+
+ test "account activity hides reconcile on a synced account" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+ synced_account = accounts(:connected)
+ entry = create_transaction(account: synced_account, name: "Synced entry")
+
+ visit account_url(synced_account, tab: "activity")
+
+ find("##{dom_id(entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ assert_no_selector "button[aria-label='#{I18n.t("transactions.selection_bar.reconcile")}']"
+ assert_selector "a[title='Edit']"
+ end
+ end
+
+ test "account activity select all includes transfer rows" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+ transfer = create_transfer(from_account: @account, to_account: accounts(:credit_card), amount: 100)
+ outflow_entry = transfer.outflow_transaction.entry
+
+ visit account_url(@account, tab: "activity")
+
+ find("#selection_entry").check
+
+ assert find("##{dom_id(outflow_entry, "selection")}").checked?
+ within "#entry-selection-bar" do
+ assert_selector "a[title='Edit']"
+ end
+ end
+
+ test "account activity filters by reconciliation status" do
+ users(:family_admin).family.update!(manual_reconciliation: true)
+ @transaction_entry.update!(reconciled_status: "cleared")
+ unreconciled = create_transaction(account: @account, name: "Unreconciled", amount: 10)
+
+ visit account_url(@account, tab: "activity")
+
+ find("#activity-filters-button").click
+
+ within "#transaction-filters-menu" do
+ find("button[data-id='reconcile_status_filter']").click
+ check I18n.t("transactions.reconcile.statuses.cleared"), allow_label_click: true
+ click_button "Apply"
+ end
+
+ assert_selector "##{dom_id(@transaction_entry)}"
+ assert_no_selector "##{dom_id(unreconciled)}"
+ assert_no_text "Content missing"
+ end
+
test "account activity keeps long category names from overflowing the amount on mobile" do
category = categories(:food_and_drink)
category.update!(name: "Super Long Category Name That Should Stop Before The Amount On Mobile")
diff --git a/test/system/account_bulk_reconciliation_test.rb b/test/system/account_bulk_reconciliation_test.rb
new file mode 100644
index 0000000000..d715cac8a4
--- /dev/null
+++ b/test/system/account_bulk_reconciliation_test.rb
@@ -0,0 +1,79 @@
+require "application_system_test_case"
+
+class AccountBulkReconciliationTest < ApplicationSystemTestCase
+ include EntriesTestHelper
+
+ setup do
+ ensure_tailwind_build
+ sign_in @user = users(:family_admin)
+ @user.family.update!(manual_reconciliation: true)
+ @account = @user.family.accounts.create!(
+ name: "[system test] Bulk reconciliation",
+ balance: 100,
+ currency: "USD",
+ accountable: Depository.new
+ )
+ @entries = [
+ create_transaction(account: @account, name: "First", amount: 10),
+ create_transaction(account: @account, name: "Second", amount: 20)
+ ]
+ end
+
+ test "reconciles every transaction from the account menu" do
+ visit account_url(@account, tab: "activity")
+
+ open_account_menu
+ click_on I18n.t("accounts.show.menu.reconcile_all.reconciled")
+ confirm_dialog
+
+ # Wait for the redirect and the re-rendered row before reading the DB. The
+ # flash is not a reliable signal: the page's morph refresh can clear it.
+ assert_selector "##{dom_id(@entries.first)} a[aria-label='#{I18n.t("transactions.reconcile.statuses.reconciled")}']"
+
+ @entries.each do |entry|
+ assert_equal "reconciled", entry.reload.reconciled_status
+ assert_selector "##{dom_id(entry)} a[aria-label='#{I18n.t("transactions.reconcile.statuses.reconciled")}']"
+ end
+ end
+
+ test "marking all unreconciled resets every transaction" do
+ @entries.each { |entry| entry.update!(reconciled_status: "reconciled") }
+ visit account_url(@account, tab: "activity")
+
+ open_account_menu
+ click_on I18n.t("accounts.show.menu.reconcile_all.unreconciled")
+ confirm_dialog
+
+ # Wait for the redirect and the re-rendered row before reading the DB. The
+ # flash is not a reliable signal: the page's morph refresh can clear it.
+ assert_selector "##{dom_id(@entries.first)} a[aria-label='#{I18n.t("transactions.reconcile.statuses.unreconciled")}']"
+
+ @entries.each do |entry|
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ assert_selector "##{dom_id(entry)} a[aria-label='#{I18n.t("transactions.reconcile.statuses.unreconciled")}']"
+ end
+ end
+
+ private
+ # The account page morph-refreshes shortly after load. Retry a detached
+ # node instead of racing the broadcast.
+ def open_account_menu
+ 3.times do
+ within_testid("account-menu") do
+ find("button").click unless has_selector?("[role='menu']", visible: true, wait: 0)
+ end
+ return if has_selector?("[role='menu']", visible: true, wait: 2)
+ rescue Selenium::WebDriver::Error::WebDriverError => e
+ raise unless e.message.match?(/does not belong to the document|stale element reference/i)
+ end
+
+ assert_selector "[role='menu']", visible: true
+ end
+
+ def confirm_dialog
+ assert_selector "#confirm-dialog[open]"
+ within("#confirm-dialog") do
+ find("button[value='confirm']:not([hidden])").click
+ end
+ end
+end
diff --git a/test/system/transactions_bulk_transfers_test.rb b/test/system/transactions_bulk_transfers_test.rb
new file mode 100644
index 0000000000..951c300923
--- /dev/null
+++ b/test/system/transactions_bulk_transfers_test.rb
@@ -0,0 +1,155 @@
+require "application_system_test_case"
+
+class TransactionsBulkTransfersTest < ApplicationSystemTestCase
+ include EntriesTestHelper
+
+ setup do
+ sign_in @user = users(:family_admin)
+ Entry.delete_all
+
+ @account = accounts(:depository)
+ @family = @user.family
+ @family.update!(manual_reconciliation: true)
+
+ @transfer = create_transfer(
+ from_account: @account,
+ to_account: accounts(:credit_card),
+ amount: 100
+ )
+ @outflow_entry = @transfer.outflow_transaction.entry
+ @inflow_entry = @transfer.inflow_transaction.entry
+ @normal_entry = create_transaction(account: @account, name: "Normal entry", amount: 10)
+
+ visit transactions_url
+ end
+
+ test "keeps edit and reconcile for a transfer and hides delete and duplicate" do
+ find("##{dom_id(@outflow_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ assert_selector "a[title='Edit']"
+ assert_selector "a[title='Duplicate'].hidden", visible: false
+ assert_selector "button[title='Delete'].hidden", visible: false
+ assert_selector "button[aria-label='#{I18n.t("transactions.selection_bar.reconcile")}']"
+ end
+ end
+
+ test "hides transfer-unsafe fields in the edit drawer" do
+ find("##{dom_id(@outflow_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ find("a[title='Edit']").click
+ end
+
+ within "#bulk_transaction_edit_drawer" do
+ assert_selector "input[name='bulk_update[name]']"
+ end
+
+ assert_no_selector "input[name='bulk_update[date]']"
+ assert_no_selector "input[name='bulk_update[category_id]']", visible: :all
+ assert_no_selector "input[name='bulk_update[merchant_id]']", visible: :all
+ assert_selector "select[name='bulk_update[tag_ids][]']"
+ assert_selector "select[name='bulk_update[reconciled_status]']"
+ assert_selector "textarea[name='bulk_update[notes]']"
+ end
+
+ test "shows category for a categorizable transfer outflow" do
+ categorizable_transfer = create_transfer(
+ from_account: @account,
+ to_account: accounts(:investment),
+ amount: 100
+ )
+ outflow_entry = categorizable_transfer.outflow_transaction.entry
+
+ visit transactions_url
+ find("##{dom_id(outflow_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ find("a[title='Edit']").click
+ end
+
+ within "#bulk_transaction_edit_drawer" do
+ assert_selector "input[name='bulk_update[name]']"
+ end
+
+ assert_selector "input[name='bulk_update[category_id]']", visible: :all
+ assert_no_selector "input[name='bulk_update[merchant_id]']", visible: :all
+ assert_no_selector "input[name='bulk_update[date]']"
+ assert_selector "select[name='bulk_update[reconciled_status]']"
+ end
+
+ test "keeps all actions for a normal selection" do
+ find("##{dom_id(@normal_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ assert_selector "a[title='Edit']"
+ assert_selector "a[title='Duplicate']"
+ assert_selector "button[title='Delete']"
+ assert_selector "button[aria-label='#{I18n.t("transactions.selection_bar.reconcile")}']"
+ end
+ end
+
+ test "keeps category and merchant for a mixed selection" do
+ find("##{dom_id(@normal_entry, "selection")}").check
+ find("##{dom_id(@outflow_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ assert_selector "a[title='Edit']"
+ assert_selector "button[title='Delete'].hidden", visible: false
+ find("a[title='Edit']").click
+ end
+
+ within "#bulk_transaction_edit_drawer" do
+ assert_selector "input[name='bulk_update[name]']"
+ end
+
+ assert_no_selector "input[name='bulk_update[date]']"
+ assert_selector "input[name='bulk_update[category_id]']", visible: :all
+ assert_selector "input[name='bulk_update[merchant_id]']", visible: :all
+ assert_selector "select[name='bulk_update[reconciled_status]']"
+ end
+
+ test "reconciles a transfer with the quick action" do
+ find("##{dom_id(@outflow_entry, "selection")}").check
+
+ within "#entry-selection-bar" do
+ find("button[aria-label='#{I18n.t("transactions.selection_bar.reconcile")}']").click
+ end
+ click_button I18n.t("transactions.reconcile.statuses.reconciled")
+
+ assert_selector "##{dom_id(@outflow_entry)} a[aria-label='#{I18n.t("transactions.reconcile.statuses.reconciled")}']"
+ assert_equal "unreconciled", @inflow_entry.reload.reconciled_status
+ end
+
+ test "disables a synced transfer leg but keeps the manual leg selectable" do
+ synced_transfer = create_transfer(
+ from_account: accounts(:connected),
+ to_account: @account,
+ amount: 100
+ )
+ synced_outflow = synced_transfer.outflow_transaction.entry
+ manual_inflow = synced_transfer.inflow_transaction.entry
+
+ visit account_url(accounts(:connected), tab: "activity")
+ assert find("##{dom_id(synced_outflow, "selection")}", visible: :all).disabled?
+
+ visit account_url(@account, tab: "activity")
+ assert_not find("##{dom_id(manual_inflow, "selection")}", visible: :all).disabled?
+ end
+
+ test "disables transfer selection when manual reconciliation is off" do
+ @family.update!(manual_reconciliation: false)
+
+ visit transactions_url
+
+ assert find("##{dom_id(@outflow_entry, "selection")}").disabled?
+ end
+
+ test "shows the reconciliation filter for a family with manual accounts" do
+ find("#transaction-filters-button").click
+
+ within "#transaction-filters-menu" do
+ assert_selector "button[data-id='reconcile_status_filter']"
+ end
+ end
+end
diff --git a/test/views/transactions/transaction_row_cache_test.rb b/test/views/transactions/transaction_row_cache_test.rb
index 9f02024f11..4641da7188 100644
--- a/test/views/transactions/transaction_row_cache_test.rb
+++ b/test/views/transactions/transaction_row_cache_test.rb
@@ -63,6 +63,14 @@ class Transactions::TransactionRowCacheTest < ActionView::TestCase
assert_not_equal base, row_key
end
+ test "the key changes when manual reconciliation is toggled" do
+ base = row_key
+
+ Current.family.update!(manual_reconciliation: true)
+
+ assert_not_equal base, row_key
+ end
+
test "renaming the merchant renders the row fresh, a balance sync does not" do
merchant = merchants(:netflix)
@transaction.update!(merchant: merchant)