Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Feature/manual transaction reconciliation (#2950)

Shibu Mf8839b9b9552
diff --git a/app/components/DS/tooltip.html.erb b/app/components/DS/tooltip.html.erb
index 4bdf82d6d9..395c34bc4d 100644
--- a/app/components/DS/tooltip.html.erb
+++ b/app/components/DS/tooltip.html.erb
@@ -13,7 +13,7 @@
class="inline-flex items-center cursor-default focus-ring rounded"
aria-describedby="<%= tooltip_id %>"
aria-label="<%= t("ds.tooltip.trigger_label", default: "More info") %>">
- <%= helpers.icon icon_name, size: size, color: color %>
+ <%= trigger_content || helpers.icon(icon_name, size: size, color: color) %>
</button>
<% else %>
<%# `as: :span` — used when the tooltip is rendered inside an
@@ -27,14 +27,26 @@
wrapper should fill an icon-only link's hit target. %>
<span class="inline-flex items-center"
aria-describedby="<%= tooltip_id %>">
- <%= helpers.icon icon_name, size: size, color: color %>
+ <%= trigger_content || helpers.icon(icon_name, size: size, color: color) %>
</span>
<% end %>
+ <%# `fixed` (with `strategy: "fixed"` in the controller) and `w-max` are both
+ load-bearing:
+
+ - `fixed` escapes ancestor `overflow: hidden`, which otherwise crops the
+ panel. The account page wraps the logo in such a row, and the default
+ `top` placement puts the panel outside its box. DS::Menu already uses
+ the fixed strategy for the same reason.
+ - `w-max` decouples the bubble from its trigger. An `absolute` panel's
+ shrink-to-fit width is bounded by its nearest *positioned* ancestor, so
+ on an icon-sized trigger the text collapsed to its longest word.
+
+ `max-w-[20rem]` on the content still wraps long copy. %>
<div role="tooltip"
id="<%= tooltip_id %>"
data-DS--tooltip-target="tooltip"
- class="<%= class_names("hidden absolute z-50", panel_classes) %>">
+ class="<%= class_names("hidden fixed z-50 w-max", panel_classes) %>">
<%# `max-w-[20rem]` scales with the root font-size so AT users with
a larger base font don't see the tooltip clipped. %>
<div class="<%= content_classes %>">
diff --git a/app/components/DS/tooltip.rb b/app/components/DS/tooltip.rb
index 1f26323c0e..d88b695423 100644
--- a/app/components/DS/tooltip.rb
+++ b/app/components/DS/tooltip.rb
@@ -2,7 +2,7 @@ class DS::Tooltip < ApplicationComponent
AS_OPTIONS = %i[button span].freeze
VARIANTS = %i[inverse surface].freeze
- attr_reader :placement, :offset, :cross_axis, :icon_name, :size, :color, :tooltip_id, :as, :html_class, :variant
+ attr_reader :placement, :offset, :cross_axis, :icon_name, :size, :color, :tooltip_id, :as, :html_class, :trigger_content, :variant
# Optional custom trigger that replaces the icon, for hover-to-reveal
# details on existing markup (e.g. a summary pill). It renders like
@@ -37,7 +37,12 @@ class DS::Tooltip < ApplicationComponent
# :surface — themed card matching the chart hover cards
# (`.chart-tooltip`), for richer content such as colored pills that
# would lose contrast on the inverse surface.
- def initialize(text: nil, placement: "top", offset: 10, cross_axis: 0, icon: "info", size: "sm", color: "default", as: :button, html_class: nil, variant: :inverse)
+ #
+ # `trigger_content:` renders raw markup in place of the default icon when
+ # `as: :span` (e.g. a reconciliation status indicator). Prefer the
+ # `trigger` slot for new usages; this option is kept for simple inline
+ # indicator markup.
+ def initialize(text: nil, placement: "top", offset: 10, cross_axis: 0, icon: "info", size: "sm", color: "default", as: :button, html_class: nil, trigger_content: nil, variant: :inverse)
raise ArgumentError, "as: must be one of #{AS_OPTIONS.inspect}" unless AS_OPTIONS.include?(as)
raise ArgumentError, "variant: must be one of #{VARIANTS.inspect}" unless VARIANTS.include?(variant.to_sym)
@@ -50,6 +55,7 @@ class DS::Tooltip < ApplicationComponent
@color = color
@as = as
@html_class = html_class
+ @trigger_content = trigger_content
@variant = variant.to_sym
@tooltip_id = "tooltip-#{SecureRandom.hex(4)}"
end
diff --git a/app/components/DS/tooltip_controller.js b/app/components/DS/tooltip_controller.js
index a036e64ff1..b378ea4b08 100644
--- a/app/components/DS/tooltip_controller.js
+++ b/app/components/DS/tooltip_controller.js
@@ -107,6 +107,11 @@ export default class extends Controller {
const reference = this.element.querySelector("[data-icon]");
computePosition(reference || this.element, this.tooltipTarget, {
placement: this.placementValue,
+ // Matches the panel's `fixed` class. An `absolute` panel is clipped by any
+ // ancestor with `overflow: hidden` — e.g. the account page header wraps
+ // the logo in exactly such a row — and its width is bounded by that
+ // ancestor rather than the text. DS::Menu uses the same strategy.
+ strategy: "fixed",
middleware: [
offset({
mainAxis: this.offsetValue,
diff --git a/app/components/UI/account_page.html.erb b/app/components/UI/account_page.html.erb
index c0b586e3dd..53273ef1c7 100644
--- a/app/components/UI/account_page.html.erb
+++ b/app/components/UI/account_page.html.erb
@@ -2,7 +2,7 @@
<%= turbo_frame_tag id do %>
<%= tag.div class: "space-y-4 pb-5 lg:pb-32" do %>
- <%= render "accounts/show/header", account: account, title: title, subtitle: subtitle %>
+ <%= render "accounts/show/header", account: account, title: title, subtitle: subtitle, reconciliation_indicator: reconciliation_indicator %>
<%= render UI::Account::Chart.new(account: account, period: chart_period, view: chart_view, loan_chart: loan_chart,
extra_repayment: extra_repayment) %>
diff --git a/app/components/UI/account_page.rb b/app/components/UI/account_page.rb
index e90e7e8c2d..2f589b66e6 100644
--- a/app/components/UI/account_page.rb
+++ b/app/components/UI/account_page.rb
@@ -1,6 +1,6 @@
class UI::AccountPage < ApplicationComponent
attr_reader :account, :chart_view, :chart_period, :loan_chart, :as_of, :statement_coverage, :statements,
- :reconciliation_statuses, :can_manage_statements
+ :reconciliation_statuses, :reconciliation_indicator, :can_manage_statements
renders_one :activity_feed, ->(feed_data:, pagy:, q:) { UI::Account::ActivityFeed.new(feed_data: feed_data, pagy: pagy, q: q) }
@@ -13,8 +13,8 @@ class UI::AccountPage < ApplicationComponent
# `loan_extra_projection` the projection with it applied, on the same
# `as_of`; nil when no extra applies.
def initialize(account:, chart_view: nil, chart_period: nil, loan_chart: nil, as_of: Date.current, active_tab: nil,
- statement_coverage: nil, statements: [], reconciliation_statuses: {}, can_manage_statements: false,
- loan_projection: nil, loan_extra_projection: nil, extra_repayment: nil)
+ statement_coverage: nil, statements: [], reconciliation_statuses: {}, reconciliation_indicator: nil,
+ can_manage_statements: false, loan_projection: nil, loan_extra_projection: nil, extra_repayment: nil)
@account = account
@chart_view = chart_view
@chart_period = chart_period
@@ -27,6 +27,7 @@ class UI::AccountPage < ApplicationComponent
@statement_coverage = statement_coverage
@statements = statements
@reconciliation_statuses = reconciliation_statuses
+ @reconciliation_indicator = reconciliation_indicator
@can_manage_statements = can_manage_statements
end
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 2c523dc0f6..7c0c051823 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -16,6 +16,11 @@ 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" })
@@ -98,6 +103,9 @@ class AccountsController < ApplicationController
# date beside a table shaded against another.
@as_of = Date.current
@accessible_account_ids = Current.user.accessible_accounts.pluck(:id).to_set
+ @reconciliation_indicator = if Current.family.manual_reconciliation?
+ Account::ReconciliationIndicator.for_accounts([ @account ])[@account.id]
+ end
@q = activity_search_params
entries = @account.entries.excluding_split_parents.search(@q, family).reverse_chronological.includes(:entryable)
if statement_tab_active?
@@ -457,7 +465,7 @@ class AccountsController < ApplicationController
def activity_search_params
q = params.fetch(:q, {}).permit(
:search, :start_date, :end_date, :amount, :amount_operator,
- categories: [], tags: [], merchants: [], types: [], status: []
+ categories: [], tags: [], merchants: [], types: [], status: [], reconcile_status: []
)
q.delete(:amount_operator) unless q[:amount].present?
q
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 5403a16731..4bb70d523f 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -47,6 +47,11 @@ 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 5711d88f7d..eb1ce24e88 100644
--- a/app/controllers/transactions/bulk_updates_controller.rb
+++ b/app/controllers/transactions/bulk_updates_controller.rb
@@ -3,6 +3,24 @@ class Transactions::BulkUpdatesController < ApplicationController
end
def create
+ # Reject an out-of-range reconciled_status before it ever reaches
+ # bulk_update! — the enum's `validate: true` means an invalid value
+ # would otherwise raise ActiveRecord::RecordInvalid partway through the
+ # bulk transaction. The single-row TransactionsController#reconcile
+ # action can't hit this (advance_reconciled_status! only ever assigns a
+ # value from RECONCILED_STATUS_CYCLE), but this form field takes
+ # arbitrary user input, so it needs the same graceful-failure handling.
+ reconciled_status = bulk_update_params[:reconciled_status]
+ if reconciled_status.present? && !Current.family.manual_reconciliation?
+ redirect_back_or_to transactions_path, alert: t("transactions.reconcile.unavailable")
+ return
+ end
+
+ if reconciled_status.present? && !Entry.reconciled_statuses.key?(reconciled_status)
+ redirect_back_or_to transactions_path, alert: t("transactions.reconcile.failure")
+ return
+ end
+
# Skip split parents from bulk update - update children instead
scoped_params = family_scoped_bulk_update_params
selected = Current.annotatable_entries
@@ -22,6 +40,21 @@ class Transactions::BulkUpdatesController < ApplicationController
end
redirect_back_or_to transactions_path, notice: "#{updated} transactions updated"
+ rescue ActiveRecord::RecordInvalid => e
+ DebugLogEntry.capture(
+ category: "reconciliation",
+ level: "error",
+ message: "Bulk transaction update failed: #{e.message}",
+ source: "Transactions::BulkUpdatesController#create",
+ family: Current.family,
+ user: Current.user,
+ metadata: {
+ error_class: e.class.name,
+ error_message: e.message,
+ entry_ids: bulk_update_params[:entry_ids]
+ }
+ )
+ redirect_back_or_to transactions_path, alert: t("transactions.reconcile.failure")
end
private
@@ -34,7 +67,7 @@ class Transactions::BulkUpdatesController < ApplicationController
def bulk_update_params
params.require(:bulk_update)
- .permit(:date, :notes, :name, :category_id, :merchant_id, entry_ids: [], tag_ids: [])
+ .permit(:date, :notes, :name, :category_id, :merchant_id, :reconciled_status, entry_ids: [], tag_ids: [])
end
# Resolve category, merchant and tag IDs through the current family so IDs
diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index ca21422a76..a6ea171228 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -452,6 +452,48 @@ class TransactionsController < ApplicationController
redirect_back_or_to transactions_path
end
+ # Advances the manual reconciled_status through unreconciled -> cleared ->
+ # reconciled -> unreconciled. Scoped to manual (unsynced) accounts — synced
+ # accounts already get duplicate-matching (Account::ProviderImportAdapter)
+ # and statement-level reconciliation (AccountStatement).
+ def reconcile
+ return head :not_found unless Current.family.manual_reconciliation?
+
+ transaction = accessible_transactions.includes(entry: :account).find(params[:id])
+ entry = transaction.entry
+
+ return unless require_account_permission!(entry.account)
+
+ unless entry.account.manual?
+ flash[:alert] = t("transactions.reconcile.not_manual_account")
+ redirect_back_or_to transactions_path
+ return
+ end
+
+ entry.advance_reconciled_status!
+ flash[:notice] = t("transactions.reconcile.success", status: t("transactions.reconcile.statuses.#{entry.reconciled_status}"))
+
+ redirect_back_or_to transactions_path
+ rescue ActiveRecord::RecordInvalid => e
+ DebugLogEntry.capture(
+ category: "reconciliation",
+ level: "error",
+ message: "Failed to update reconciled_status for transaction #{params[:id]}: #{e.message}",
+ source: "TransactionsController#reconcile",
+ family: Current.family,
+ user: Current.user,
+ account: entry&.account,
+ metadata: {
+ transaction_id: params[:id],
+ entry_id: entry&.id,
+ error_class: e.class.name,
+ error_message: e.message
+ }
+ )
+ flash[:alert] = t("transactions.reconcile.failure")
+ redirect_back_or_to transactions_path
+ end
+
def mark_as_recurring
transaction = accessible_transactions.includes(entry: :account).find(params[:id])
@@ -803,7 +845,7 @@ class TransactionsController < ApplicationController
:amount_operator, :active_accounts_only,
accounts: [], account_ids: [],
categories: [], merchants: [], types: [], tags: [], status: [], ai_status: [],
- attachment_status: []
+ attachment_status: [], reconcile_status: []
)
.to_h
.compact_blank
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index d024b77b44..6faa70e2cb 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -116,7 +116,7 @@ class UsersController < ApplicationController
def user_params
family_attrs = [ :name, :currency, :country, :date_format, :timezone, :locale, :month_start_day, :id ]
if Current.user.admin?
- family_attrs.push(:personal_budgets, :household_budget_enabled, :investment_contributions_as_spending) # Needed for updating existing family
+ family_attrs.push(:personal_budgets, :household_budget_enabled, :investment_contributions_as_spending, :manual_reconciliation) # Needed for updating existing family
family_attrs.push(:moniker, :default_account_sharing)
family_attrs << { enabled_currencies: [] }
end
@@ -144,9 +144,10 @@ class UsersController < ApplicationController
personal_budgets_changed = family_attrs.key?(:personal_budgets)
household_budget_enabled_changed = family_attrs.key?(:household_budget_enabled)
investment_contributions_as_spending_changed = family_attrs.key?(:investment_contributions_as_spending)
+ manual_reconciliation_changed = family_attrs.key?(:manual_reconciliation)
moniker_changed || sharing_changed || enabled_currencies_changed || personal_budgets_changed || household_budget_enabled_changed ||
- investment_contributions_as_spending_changed
+ investment_contributions_as_spending_changed || manual_reconciliation_changed
end
def ensure_admin
diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb
index 73f861b80c..84aa67a277 100644
--- a/app/helpers/accounts_helper.rb
+++ b/app/helpers/accounts_helper.rb
@@ -71,6 +71,7 @@ module AccountsHelper
[
family.build_cache_key("account_sidebar_tabs_v7", invalidate_on_data_updates: true),
+ family.manual_reconciliation?,
Current.user&.id,
shares_version,
providers_version,
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/transactions_helper.rb
index 095dade75f..f8b69d00b0 100644
--- a/app/helpers/transactions_helper.rb
+++ b/app/helpers/transactions_helper.rb
@@ -5,7 +5,7 @@ module TransactionsHelper
# @return [Array<Hash>] the filters offered above the transaction list, each
# with the key its partial is named for, a translated label and an icon
def transaction_search_filters(exclude: [])
- [
+ filters = [
{ key: "account_filter", label: t("transactions.search.filters.account"), icon: "layers" },
{ key: "date_filter", label: t("transactions.search.filters.date"), icon: "calendar" },
{ key: "type_filter", label: t("transactions.search.filters.type"), icon: "tag" },
@@ -16,7 +16,13 @@ module TransactionsHelper
{ key: "merchant_filter", label: t("transactions.search.filters.merchant"), icon: "store" },
{ key: "ai_filter", label: t("transactions.search.filters.ai"), icon: "sparkles" },
{ key: "attachment_filter", label: t("transactions.search.filters.attachment"), icon: "paperclip" }
- ].reject { |filter| exclude.include?(filter[:key]) }
+ ]
+
+ if Current.family&.manual_reconciliation?
+ filters.insert(4, { key: "reconcile_status_filter", label: t("transactions.search.filters.reconcile_status"), icon: "check-circle" })
+ end
+
+ filters.reject { |filter| exclude.include?(filter[:key]) }
end
# @param label [String] a stored investment_activity_label such as "Sweep In"
@@ -61,6 +67,30 @@ module TransactionsHelper
entry.split_child? && Current.user.show_split_grouped? && params_grouped == "true"
end
+ # Single source of truth for how each reconciled_status renders — used by
+ # both the transaction row/detail badge (_reconcile_badge.html.erb) and the
+ # bulk-reconcile selection-bar menu (_selection_bar.html.erb), so the two
+ # can't silently drift out of sync.
+ RECONCILE_STATUS_PRESENTATION = {
+ "unreconciled" => { tone: :neutral, icon: "circle", text_class: "text-secondary" },
+ "cleared" => { tone: :warning, icon: "circle-dot", text_class: "text-warning" },
+ "reconciled" => { tone: :success, icon: "check-circle", text_class: "text-success" }
+ }.freeze
+
+ def reconcile_status_tone(status)
+ RECONCILE_STATUS_PRESENTATION.fetch(status, RECONCILE_STATUS_PRESENTATION["unreconciled"])[:tone]
+ end
+
+ def reconcile_status_icon(status)
+ RECONCILE_STATUS_PRESENTATION.fetch(status, RECONCILE_STATUS_PRESENTATION["unreconciled"])[:icon]
+ end
+
+ # Foreground token for the compact, icon-only indicator rendered in the
+ # transaction list row, where there is no room for a labelled pill.
+ def reconcile_status_text_class(status)
+ RECONCILE_STATUS_PRESENTATION.fetch(status, RECONCILE_STATUS_PRESENTATION["unreconciled"])[:text_class]
+ end
+
# Files whose content shapes a cached transaction row; see
# transaction_row_cache_key.
TRANSACTION_ROW_SOURCES = %w[
@@ -126,6 +156,7 @@ module TransactionsHelper
# The "Transfer?" hint is drawn inside the cached row.
@transfer_hint_transaction_ids&.include?(transaction.id) || false,
can_annotate_account?(entry.account),
+ can_reconcile_account?(entry.account),
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) },
@@ -152,6 +183,20 @@ module TransactionsHelper
@annotatable_account_ids.include?(account.id)
end
+ # Whether the current user may cycle the manual reconciliation status.
+ # TransactionsController#reconcile requires write access (see
+ # require_account_permission! in AccountAuthorizable), so the badge must
+ # only be offered on accounts the user owns or holds full_control on --
+ # otherwise the click is rejected and the status never advances. Matches
+ # the "write" predicate rather than the annotate one, since reconciling is
+ # not an annotation. Memoized per request so list rows don't query per row.
+ def can_reconcile_account?(account)
+ return false unless Current.user
+
+ @reconcilable_account_ids ||= Account.writable_by(Current.user).pluck(:id).to_set
+ @reconcilable_account_ids.include?(account.id)
+ 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/clickable_row_controller.js b/app/javascript/controllers/clickable_row_controller.js
index b1dda43e39..72c5739fcd 100644
--- a/app/javascript/controllers/clickable_row_controller.js
+++ b/app/javascript/controllers/clickable_row_controller.js
@@ -9,7 +9,12 @@ export default class extends Controller {
static targets = ["link"];
open(event) {
- if (event.target.closest("a, button, input, select, textarea, label")) return;
+ if (event.target.closest("a, button, input, select, textarea, label"))
+ return;
+ // Passive markers (e.g. the account reconciliation flag in the accounts
+ // list) sit inside the row but are not controls, so a click on one is not
+ // a request to open the row either.
+ if (event.target.closest("[data-row-click-ignore]")) return;
// Popover/menu/dropdown panels (category dropdown, account/kebab menu,
// investment activity quick-edit) render as `position: fixed`/`absolute`
// but stay DOM descendants of the row, so a click anywhere on their
diff --git a/app/models/account/reconciliation_indicator.rb b/app/models/account/reconciliation_indicator.rb
new file mode 100644
index 0000000000..bdafe29e78
--- /dev/null
+++ b/app/models/account/reconciliation_indicator.rb
@@ -0,0 +1,78 @@
+class Account::ReconciliationIndicator
+ class << self
+ def for_accounts(accounts)
+ account_list = accounts.to_a
+ return {} if account_list.empty?
+
+ account_ids = account_list.map(&:id)
+ manual_reconciliation_available = Entry.connection.column_exists?(:entries, :reconciled_status)
+ manual_account_ids = if manual_reconciliation_available
+ Account.manual.where(id: account_ids).pluck(:id).to_set
+ else
+ Set.new
+ end
+ statement_account_ids = account_ids - manual_account_ids.to_a
+ statements_by_account = latest_statements_by_account(statement_account_ids)
+ transaction_counts = Entry.where(account_id: account_ids, entryable_type: "Transaction", excluded: false).group(:account_id).count
+ statement_unreconciled_entries = Entry.where(account_id: statement_account_ids, entryable_type: "Transaction", excluded: false, reconciled_at: nil)
+ statement_unreconciled_counts = statement_unreconciled_entries.group(:account_id).count
+ statement_unreconciled_dates = statement_unreconciled_entries.pluck(:account_id, :date).group_by(&:first).transform_values { |entries| entries.map(&:last) }
+ manual_unreconciled_counts = if manual_reconciliation_available
+ Entry.where(account_id: manual_account_ids, entryable_type: "Transaction", excluded: false)
+ .where.not(reconciled_status: "reconciled")
+ .group(:account_id)
+ .count
+ else
+ {}
+ end
+ balances_by_key = balances_for(statements_by_account.values)
+
+ account_list.to_h do |account|
+ if manual_account_ids.include?(account.id)
+ all_transactions_reconciled = transaction_counts[account.id].to_i.positive? && manual_unreconciled_counts[account.id].to_i.zero?
+ status = all_transactions_reconciled ? :matched : (:needs_attention if transaction_counts[account.id].to_i.positive?)
+ next [ account.id, status ]
+ end
+
+ statement = statements_by_account[account.id]
+ statement_status = statement&.reconciliation_status(
+ balance_lookup: ->(date, currency) { balances_by_key[[ account.id, date, currency ]] }
+ )
+ all_transactions_reconciled = transaction_counts[account.id].to_i.positive? && statement_unreconciled_counts[account.id].to_i.zero?
+ newer_unreconciled_transactions = statement&.period_end_on.present? &&
+ statement_unreconciled_dates.fetch(account.id, []).any? { |date| date > statement.period_end_on }
+
+ status = if statement_status == "mismatched"
+ :needs_attention
+ elsif statement_status == "matched" && !newer_unreconciled_transactions
+ :matched
+ elsif all_transactions_reconciled
+ :matched
+ elsif statement.present? || transaction_counts[account.id].to_i.positive?
+ :needs_attention
+ end
+
+ [ account.id, status ]
+ end
+ end
+
+ private
+ def latest_statements_by_account(account_ids)
+ AccountStatement.where(account_id: account_ids).order(account_id: :asc, created_at: :desc).to_a
+ .group_by(&:account_id)
+ .transform_values(&:first)
+ end
+
+ def balances_for(statements)
+ return {} if statements.empty?
+
+ account_ids = statements.map(&:account_id)
+ dates = statements.flat_map { |statement| [ statement.period_start_on, statement.period_end_on ] }.compact.uniq
+ currencies = statements.map(&:statement_currency).compact.uniq
+
+ Balance.where(account_id: account_ids, date: dates, currency: currencies).index_by do |balance|
+ [ balance.account_id, balance.date, balance.currency ]
+ end
+ end
+ end
+end
diff --git a/app/models/entry.rb b/app/models/entry.rb
index 00a1d9117a..f0a7f04d4f 100644
--- a/app/models/entry.rb
+++ b/app/models/entry.rb
@@ -33,6 +33,32 @@ class Entry < ApplicationRecord
delegated_type :entryable, types: Entryable::TYPES, dependent: :destroy, inverse_of: :entry
accepts_nested_attributes_for :entryable
+ # Manual, Bluecoins-style reconciliation status. Distinct from Transaction#pending?
+ # (which reflects the bank/provider's own pending-vs-posted status) and from the
+ # sync-time duplicate-claim logic in Account::ProviderImportAdapter (which already
+ # auto-matches/merges manual entries against later bank-synced transactions).
+ #
+ # This is a user-controlled flag for manually checking entries off against a
+ # paper/PDF statement — line-by-line, the way a checkbook register works. The
+ # column exists on every entry, but the UI only surfaces it for manual
+ # (unsynced) accounts, i.e. `account.manual?` — synced accounts already have
+ # duplicate-matching (Account::ProviderImportAdapter) and statement-level
+ # reconciliation (AccountStatement, Account::ReconciliationManager).
+ # Declare the type explicitly so the enum remains bootable while a long-lived
+ # web process refreshes its schema metadata after the column migration.
+ attribute :reconciled_status, :string, default: "unreconciled"
+ enum :reconciled_status, {
+ unreconciled: "unreconciled", # default — not yet checked against a statement
+ cleared: "cleared", # confirmed to appear on a statement, not yet locked in
+ reconciled: "reconciled" # statement period fully reconciled; treat as locked
+ }, default: "unreconciled", validate: true
+
+ # Order the manual reconciliation status advances through when a user
+ # clicks the reconcile badge, e.g. on the transaction row or detail view.
+ # Derived from the enum (not hardcoded) so it can't drift from it if a
+ # status is ever renamed or added.
+ RECONCILED_STATUS_CYCLE = reconciled_statuses.keys.freeze
+
validates :date, :name, :amount, :currency, presence: true
validates :date, uniqueness: { scope: [ :account_id, :entryable_type ] }, if: -> { valuation? }
validates :date, comparison: { greater_than: -> { min_supported_date } }
@@ -46,14 +72,14 @@ class Entry < ApplicationRecord
# decided blank-name handling) and any unrelated re-validation of an
# already-persisted entry (background jobs, resaves) that happens to see
# a blank name for some other reason. external_id/source are also excluded
- # (via !cleared?) because Account::ProviderImportAdapter sets both at
+ # (via !statement_cleared?) because Account::ProviderImportAdapter sets both at
# find_or_initialize_by time, before this callback runs -- without that
# guard, a first-time sync of a provider transaction with no name (e.g.
# Plaid omitting both merchant_name and original_description) would get a
# synthetic "Category - Merchant" name instead of surfacing the blank-name
# presence error the same way a manual blank submission would.
before_validation :set_default_name, if: -> {
- new_record? && import_id.blank? && name.blank? && !cleared? &&
+ new_record? && import_id.blank? && name.blank? && !statement_cleared? &&
entryable_type == "Transaction" && account&.family&.auto_generate_transaction_names?
}
@@ -82,10 +108,18 @@ class Entry < ApplicationRecord
)
}
- # Reconciliation scopes - see AddReconciliationToEntries
- scope :reconciled, -> { where.not(reconciled_at: nil) }
- scope :unreconciled, -> { where(reconciled_at: nil) }
- scope :reconciled_by, ->(statement) { where(reconciled_by_statement_id: statement) }
+ # Manual reconciliation scopes (see reconciled_status enum above)
+ scope :needs_reconciliation, -> { where(reconciled_status: [ :unreconciled, :cleared ]) }
+ scope :cleared_or_reconciled, -> { where(reconciled_status: [ :cleared, :reconciled ]) }
+
+ # Statement-import reconciliation scopes - see AddReconciliationToEntries.
+ # Named distinctly from the reconciled_status enum's auto-generated
+ # `reconciled` / `unreconciled` scopes above (different concept: this is
+ # import-time dedup against AccountStatement, not the manual clear/reconcile
+ # toggle on manual accounts).
+ scope :statement_reconciled, -> { where.not(reconciled_at: nil) }
+ scope :statement_unreconciled, -> { where(reconciled_at: nil) }
+ scope :reconciled_by_statement, ->(statement) { where(reconciled_by_statement_id: statement) }
# Pending transaction scopes - check Transaction.extra for provider pending flags
# Works with any provider that stores pending status in extra["provider_name"]["pending"]
@@ -402,8 +436,8 @@ class Entry < ApplicationRecord
#
# @return [Symbol] :uncleared, :cleared or :reconciled
def reconciliation_state
- return :reconciled if reconciled?
- return :cleared if cleared?
+ return :reconciled if statement_reconciled?
+ return :cleared if statement_cleared?
:uncleared
end
@@ -413,14 +447,20 @@ class Entry < ApplicationRecord
# external_id and source -- see Account::ProviderImportAdapter). Derived rather
# than stored so it cannot drift, and deliberately not user-settable: this is a
# fact about where the entry came from, not an opinion about it.
- def cleared?
+ #
+ # Named distinctly from the reconciled_status enum's auto-generated `cleared?`
+ # (manual clear/reconcile toggle on manual accounts -- a different concept).
+ def statement_cleared?
external_id.present? || source.present?
end
- # A statement has been matched against this transaction. Unlike cleared?, this
- # is a judgement -- made by a statement import, or by the user directly -- so
- # it is stored and can be undone.
- def reconciled?
+ # A statement has been matched against this transaction. Unlike
+ # statement_cleared?, this is a judgement -- made by a statement import, or by
+ # the user directly -- so it is stored and can be undone.
+ #
+ # Named distinctly from the reconciled_status enum's auto-generated
+ # `reconciled?` (manual clear/reconcile toggle on manual accounts).
+ def statement_reconciled?
reconciled_at.present?
end
@@ -611,6 +651,16 @@ class Entry < ApplicationRecord
end
end
+ # Advances reconciled_status to the next state in RECONCILED_STATUS_CYCLE,
+ # wrapping back to :unreconciled after :reconciled. Used by the quick-toggle
+ # UI control so a single click/tap moves a transaction through the same
+ # None -> Cleared -> Reconciled flow Bluecoins uses.
+ def advance_reconciled_status!
+ current_index = RECONCILED_STATUS_CYCLE.index(reconciled_status) || 0
+ next_status = RECONCILED_STATUS_CYCLE[(current_index + 1) % RECONCILED_STATUS_CYCLE.length]
+ update!(reconciled_status: next_status)
+ end
+
# Removes split children and restores parent entry.
def unsplit!
self.class.transaction do
@@ -658,6 +708,7 @@ class Entry < ApplicationRecord
date: bulk_update_params[:date],
notes: bulk_update_params[:notes],
name: bulk_update_params[:name],
+ reconciled_status: bulk_update_params[:reconciled_status],
entryable_attributes: {
category_id: bulk_update_params[:category_id],
merchant_id: bulk_update_params[:merchant_id]
@@ -669,19 +720,32 @@ class Entry < ApplicationRecord
return 0 unless has_updates
+ updated_count = 0
+
# account_id => earliest of old/new date, for entries whose date moved
sync_windows = {}
rescheduled_ids = []
transaction do
- all.each do |entry|
+ all.includes(:account).each do |entry|
changed = false
+ # Whether this row's changes should lock saved attributes / mark
+ # user-modified. Reconciling is a verification action, not an
+ # edit — the single-row Entry#advance_reconciled_status! (used by
+ # the quick-toggle badge) never locks anything, so a bulk
+ # reconcile-only update shouldn't either. If reconciled_status is
+ # combined with a real edit (category, notes, etc.) in the same
+ # bulk update, the usual locking still applies to those fields.
+ lockable_change = false
# Update standard attributes
if bulk_attributes.present?
attrs = bulk_attributes.dup
attrs.delete(:date) if entry.split_child?
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?
if attrs.present?
attrs[:entryable_attributes] = attrs[:entryable_attributes].dup if attrs[:entryable_attributes].present?
@@ -689,6 +753,7 @@ class Entry < ApplicationRecord
entry.update! attrs
entry.transaction.record_category_usage! if entry.transaction?
changed = true
+ lockable_change = attrs.except(:reconciled_status).present?
if entry.saved_change_to_date?
window_start = entry.saved_change_to_date.compact.min
@@ -704,11 +769,15 @@ class Entry < ApplicationRecord
entry.transaction.save!
entry.entryable.lock_attr!(:tag_ids) if entry.transaction.tags.any?
changed = true
+ lockable_change = true
end
if changed
- entry.lock_saved_attributes!
- entry.mark_user_modified!
+ if lockable_change
+ entry.lock_saved_attributes!
+ entry.mark_user_modified!
+ end
+ updated_count += 1
end
end
end
@@ -718,7 +787,7 @@ class Entry < ApplicationRecord
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?
- all.size
+ updated_count
end
end
diff --git a/app/models/family.rb b/app/models/family.rb
index 4a71947c26..8c7bab53c1 100644
--- a/app/models/family.rb
+++ b/app/models/family.rb
@@ -258,6 +258,7 @@ class Family < ApplicationRecord
validates :household_budget_enabled, inclusion: { in: [ true, false ] }
validates :auto_generate_transaction_names, inclusion: { in: [ true, false ] }
validates :investment_contributions_as_spending, inclusion: { in: [ true, false ] }
+ validates :manual_reconciliation, inclusion: { in: [ true, false ] }
validates :categories_locked, inclusion: { in: [ true, false ] }
# The searchable timezone select submits "" while no zone is saved yet;
# store nil so provider date parsing keeps its default instead of raising.
diff --git a/app/models/pdf_import.rb b/app/models/pdf_import.rb
index ccf8c6adc5..fbecbea913 100644
--- a/app/models/pdf_import.rb
+++ b/app/models/pdf_import.rb
@@ -340,7 +340,7 @@ class PdfImport < Import
def reconciled_entries
return Entry.none if account_statement.blank?
- Entry.reconciled_by(account_statement)
+ Entry.reconciled_by_statement(account_statement)
end
# The half of reconciled_entries this import did not create -- transactions the
@@ -549,7 +549,7 @@ class PdfImport < Import
def release_reconciliations!(account_scope_id)
return if account_statement.blank? || account_scope_id.blank?
- Entry.reconciled_by(account_statement).where(account_id: account_scope_id).update_all(
+ Entry.reconciled_by_statement(account_statement).where(account_id: account_scope_id).update_all(
reconciled_at: nil,
reconciled_by_statement_id: nil,
updated_at: Time.current
diff --git a/app/models/transaction/search.rb b/app/models/transaction/search.rb
index 2c541e332f..a6db0e74b5 100644
--- a/app/models/transaction/search.rb
+++ b/app/models/transaction/search.rb
@@ -153,6 +153,7 @@ class Transaction::Search
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
@@ -186,6 +187,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_merchant_filter(query, merchants)
query = self.class.apply_tag_filter(query, tags)
query = apply_ai_status_filter(query, ai_status)
@@ -374,4 +376,26 @@ 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 c46ccda654..174145ae34 100644
--- a/app/views/accounts/_account.html.erb
+++ b/app/views/accounts/_account.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (account:, return_to: nil) %>
+<%# locals: (account:, return_to: nil, reconciliation_indicator: 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" %>
+ <%= render "accounts/logo", account: account, size: "md", reconciliation_indicator: reconciliation_indicator %>
<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 f044fe9011..1e8d83d9a1 100644
--- a/app/views/accounts/_account_sidebar_tabs.html.erb
+++ b/app/views/accounts/_account_sidebar_tabs.html.erb
@@ -10,6 +10,11 @@
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",
@@ -57,7 +62,7 @@
<div>
<% family.balance_sheet.assets.account_groups.each do |group| %>
- <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable %>
+ <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable, reconciliation_indicators: reconciliation_indicators %>
<% end %>
</div>
</div>
@@ -89,7 +94,7 @@
<div>
<% family.balance_sheet.liabilities.account_groups.each do |group| %>
- <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable %>
+ <%= render "accounts/accountable_group", account_group: group, mobile: mobile, sortable: sortable, reconciliation_indicators: reconciliation_indicators %>
<% end %>
</div>
</div>
@@ -121,7 +126,7 @@
<div>
<% family.balance_sheet.account_groups.each do |group| %>
- <%= render "accounts/accountable_group", account_group: group, mobile: mobile, all_tab: true, sortable: sortable %>
+ <%= render "accounts/accountable_group", account_group: group, mobile: mobile, all_tab: true, sortable: sortable, reconciliation_indicators: reconciliation_indicators %>
<% end %>
</div>
</div>
diff --git a/app/views/accounts/_accountable_group.html.erb b/app/views/accounts/_accountable_group.html.erb
index 28668cf01a..87d91b52db 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, **args) %>
+<%# locals: (account_group:, mobile: false, all_tab: false, open: nil, sortable: false, reconciliation_indicators: {}, **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 %>
+ <%= render "accounts/logo", account: account, size: "sm", color: account_group.color, reconciliation_indicator: reconciliation_indicators[account.id] %>
<div class="min-w-0 grow">
<div class="flex items-center gap-2 mb-0.5">
diff --git a/app/views/accounts/_logo.html.erb b/app/views/accounts/_logo.html.erb
index a553f27eba..86ab70fae6 100644
--- a/app/views/accounts/_logo.html.erb
+++ b/app/views/accounts/_logo.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (account:, size: "md", color: nil, url: account.logo_url) %>
+<%# locals: (account:, size: "md", color: nil, url: account.logo_url, reconciliation_indicator: nil) %>
<% size_classes = {
"sm" => "w-6 h-6",
@@ -15,18 +15,60 @@
rounded: true
} %>
-<% if url.present? %>
- <%# The ProviderLogo recipe: the initials sit under the image, and a logo the
- browser cannot show (an upload whose file is gone, a dead favicon or
- Brandfetch URL) removes itself to reveal them. %>
- <%= tag.span class: "relative block shrink-0 #{size_classes[size]}" do %>
- <%= render DS::FilledIcon.new(**initials, class_name: "absolute inset-0 w-full! h-full!") %>
- <%= image_tag url,
- class: "absolute inset-0 w-full h-full rounded-full object-contain bg-container",
- alt: "",
- loading: "lazy",
- onerror: ProviderLogo::REMOVE_ON_ERROR %>
+<div class="relative shrink-0">
+ <% if url.present? %>
+ <%# The ProviderLogo recipe: the initials sit under the image, and a logo the
+ browser cannot show (an upload whose file is gone, a dead favicon or
+ Brandfetch URL) removes itself to reveal them. %>
+ <%= tag.span class: "relative block shrink-0 #{size_classes[size]}" do %>
+ <%= render DS::FilledIcon.new(**initials, class_name: "absolute inset-0 w-full! h-full!") %>
+ <%= image_tag url,
+ class: "absolute inset-0 w-full h-full rounded-full object-contain bg-container",
+ alt: "",
+ loading: "lazy",
+ onerror: ProviderLogo::REMOVE_ON_ERROR %>
+ <% end %>
+ <% else %>
+ <%= render DS::FilledIcon.new(**initials) %>
<% end %>
-<% else %>
- <%= render DS::FilledIcon.new(**initials) %>
-<% end %>
+
+ <% if reconciliation_indicator.present? %>
+ <%#
+ Status only, never an action — the account itself offers no
+ reconciliation control, so the tooltip explains the colour on hover and
+ is exposed to AT via aria-describedby.
+
+ The corner offset lives on the tooltip wrapper (`html_class:`), not on
+ the dot. The wrapper is inline-level, so in flow it opens a line box
+ inside the logo's `relative` container and grows that container — which
+ pushed the `absolute` dot clear of the corner. Out of flow, the wrapper
+ sizes to the dot and anchors to the container as intended.
+
+ The dot carries `data-row-click-ignore` so a click on it doesn't open the
+ account row (ClickableRowController#open).
+ %>
+ <% matched = reconciliation_indicator == :matched %>
+ <% if matched %>
+ <%= render DS::Tooltip.new(
+ text: t("accounts.reconciliation_indicator.matched"),
+ as: :span,
+ html_class: "absolute -bottom-0.5 -right-0.5",
+ trigger_content: tag.span(
+ icon("check", class: "w-2 h-2 text-inverse"),
+ class: "flex h-3 w-3 items-center justify-center rounded-full border border-container bg-success",
+ data: { row_click_ignore: true }
+ )
+ ) %>
+ <% else %>
+ <%= render DS::Tooltip.new(
+ text: t("accounts.reconciliation_indicator.needs_attention"),
+ as: :span,
+ html_class: "absolute -bottom-0.5 -right-0.5",
+ trigger_content: tag.span(
+ class: "h-2.5 w-2.5 rounded-full border border-container bg-warning",
+ data: { row_click_ignore: true }
+ )
+ ) %>
+ <% end %>
+ <% end %>
+</div>
diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb
index 9eeec24b04..5ae5883561 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 %>
+ <%= render "accounts/index/manual_accounts", accounts: @manual_accounts, reconciliation_indicators: @reconciliation_indicators %>
</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 2f1ecef360..7e4a5c1a50 100644
--- a/app/views/accounts/index/_account_groups.erb
+++ b/app/views/accounts/index/_account_groups.erb
@@ -1,4 +1,4 @@
-<%# locals: (accounts:) %>
+<%# locals: (accounts:, reconciliation_indicators: {}) %>
<% 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 %>
+ <%= render "accounts/account", account: account, reconciliation_indicator: reconciliation_indicators[account.id] %>
<% 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 97c08ac07e..14187735fd 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:) %>
+<%# locals: (accounts:, reconciliation_indicators: {}) %>
<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 %>
+ <%= render "accounts/index/account_groups", accounts: accounts, reconciliation_indicators: reconciliation_indicators %>
</div>
</details>
diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb
index db5eb278ec..47afc5be1c 100644
--- a/app/views/accounts/show.html.erb
+++ b/app/views/accounts/show.html.erb
@@ -11,6 +11,7 @@
statement_coverage: @statement_coverage,
statements: @account_statements,
reconciliation_statuses: @statement_reconciliation_statuses,
+ reconciliation_indicator: @reconciliation_indicator,
can_manage_statements: @can_manage_statements
) do |account_page| %>
<%= account_page.with_activity_feed(feed_data: @activity_feed_data, pagy: @pagy, q: @q) %>
diff --git a/app/views/accounts/show/_header.html.erb b/app/views/accounts/show/_header.html.erb
index ddbad5a2bd..3077bd6e35 100644
--- a/app/views/accounts/show/_header.html.erb
+++ b/app/views/accounts/show/_header.html.erb
@@ -1,9 +1,9 @@
-<%# locals: (account:, title:, subtitle: nil) %>
+<%# locals: (account:, title:, subtitle: nil, reconciliation_indicator: nil) %>
<header class="space-y-4">
<div class="flex items-center gap-4">
<div class="flex items-center gap-3 overflow-hidden">
- <%= render "accounts/logo", account: account %>
+ <%= render "accounts/logo", account: account, reconciliation_indicator: reconciliation_indicator %>
<div class="flex items-center gap-2">
<div class="truncate">
diff --git a/app/views/pages/dashboard/_balance_sheet.html.erb b/app/views/pages/dashboard/_balance_sheet.html.erb
index 9b88898bff..928dc98f0f 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 %>
+ <%= render "accounts/logo", account: account, size: "sm", color: account_group.color, reconciliation_indicator: @reconciliation_indicators[account.id] %>
<%= link_to account.name, account_path(account) %>
</div>
diff --git a/app/views/settings/preferences/show.html.erb b/app/views/settings/preferences/show.html.erb
index ead2553844..c3577a2ecf 100644
--- a/app/views/settings/preferences/show.html.erb
+++ b/app/views/settings/preferences/show.html.erb
@@ -38,6 +38,29 @@
<% end %>
</div>
<% end %>
+<% if Current.user.admin? && preview_features_enabled? %>
+ <%= settings_section title: t(".transactions_title"), subtitle: t(".transactions_subtitle") do %>
+ <div>
+ <%= styled_form_with model: @user, class: "space-y-4", data: { controller: "auto-submit-form" } do |form| %>
+ <%= form.hidden_field :redirect_to, value: "preferences" %>
+ <%= form.fields_for :family do |family_form| %>
+ <div class="flex items-center justify-between gap-4">
+ <div class="space-y-1">
+ <p class="text-sm flex items-center gap-1.5" id="manual_reconciliation_label">
+ <%= t(".manual_reconciliation") %>
+ <%= render DS::Pill.new(label: t("shared.preview"), size: :sm) %>
+ </p>
+ <p class="text-secondary text-sm"><%= t(".manual_reconciliation_hint") %></p>
+ </div>
+ <%= family_form.toggle :manual_reconciliation,
+ "aria-labelledby": "manual_reconciliation_label",
+ data: { auto_submit_form_target: "auto" } %>
+ </div>
+ <% end %>
+ <% end %>
+ </div>
+ <% end %>
+<% end %>
<%= settings_section title: t(".budget_title"), subtitle: t(".budget_subtitle") do %>
<div>
<%= styled_form_with model: @user, class: "space-y-4", data: { controller: "auto-submit-form" } do |form| %>
diff --git a/app/views/transactions/_header.html.erb b/app/views/transactions/_header.html.erb
index 26fcacd942..af4549a190 100644
--- a/app/views/transactions/_header.html.erb
+++ b/app/views/transactions/_header.html.erb
@@ -17,7 +17,7 @@
</span>
<% end %>
</h3>
- <div class="flex items-center gap-2">
+ <div class="flex flex-wrap items-center gap-2">
<span class="text-sm text-secondary">
<%= entry.date ? I18n.l(entry.date, format: :long) : "—" %>
</span>
@@ -30,6 +30,7 @@
title: t("transactions.transaction.pending_tooltip")
) %>
<% end %>
+ <%= render "transactions/reconcile_badge", entry: entry %>
</div>
</div>
</div>
diff --git a/app/views/transactions/_reconcile_badge.html.erb b/app/views/transactions/_reconcile_badge.html.erb
new file mode 100644
index 0000000000..93eea867d9
--- /dev/null
+++ b/app/views/transactions/_reconcile_badge.html.erb
@@ -0,0 +1,36 @@
+<%# locals: (entry:, compact: false) %>
+<%# Manual reconciliation status — only meaningful for manual (unsynced) accounts.
+ Synced accounts already have duplicate-matching + statement-level reconciliation
+ (see Entry#reconciled_status for the full rationale).
+
+ Gated on write access as well: #reconcile requires it, so a read_write or
+ read_only share must not be offered a control the server would reject. %>
+<% if Current.family&.manual_reconciliation? && entry.account.manual? && can_reconcile_account?(entry.account) %>
+ <%
+ status = entry.reconciled_status
+ tooltip = t("transactions.reconcile.badge.#{status}_tooltip")
+ %>
+ <%= link_to reconcile_transaction_path(entry.transaction),
+ data: { turbo_method: :patch, turbo_frame: "_top" },
+ aria: { label: t("transactions.reconcile.statuses.#{status}") },
+ class: "hover:opacity-80 transition-opacity flex items-center" do %>
+ <% if compact %>
+ <%= render DS::Tooltip.new(
+ text: tooltip,
+ as: :span,
+ trigger_content: tag.span(
+ icon(reconcile_status_icon(status), size: "sm", color: "current"),
+ class: reconcile_status_text_class(status)
+ )
+ ) %>
+ <% else %>
+ <%= render DS::Pill.new(
+ label: t("transactions.reconcile.statuses.#{status}"),
+ tone: reconcile_status_tone(status),
+ marker: false,
+ icon: reconcile_status_icon(status),
+ title: tooltip
+ ) %>
+ <% end %>
+ <% end %>
+<% end %>
diff --git a/app/views/transactions/_selection_bar.html.erb b/app/views/transactions/_selection_bar.html.erb
index bfec49418c..34c7f8968d 100644
--- a/app/views/transactions/_selection_bar.html.erb
+++ b/app/views/transactions/_selection_bar.html.erb
@@ -25,6 +25,31 @@
<%= 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 %>
+
<%= 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">
<%= icon "trash-2", class: "group-hover/delete:text-inverse" %>
diff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erb
index da77dfe2b1..48ec9352e9 100644
--- a/app/views/transactions/_transaction.html.erb
+++ b/app/views/transactions/_transaction.html.erb
@@ -97,6 +97,9 @@
</span>
<% end %>
+ <%# Manual reconciliation status (manual accounts only) %>
+ <%= render "transactions/reconcile_badge", entry: entry, compact: true %>
+
<%# Scheduled (future-dated) indicator %>
<% if entry.scheduled? %>
<%= render DS::Pill.new(
diff --git a/app/views/transactions/bulk_updates/new.html.erb b/app/views/transactions/bulk_updates/new.html.erb
index 5b8f090583..a342438acb 100644
--- a/app/views/transactions/bulk_updates/new.html.erb
+++ b/app/views/transactions/bulk_updates/new.html.erb
@@ -14,6 +14,12 @@
<%= 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" } %>
<%= 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? %>
+ <%= 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 %>
</div>
<% end %>
diff --git a/app/views/transactions/searches/filters/_badge.html.erb b/app/views/transactions/searches/filters/_badge.html.erb
index c8c60ab2e2..e374b6b255 100644
--- a/app/views/transactions/searches/filters/_badge.html.erb
+++ b/app/views/transactions/searches/filters/_badge.html.erb
@@ -49,6 +49,11 @@
<div class="flex items-center gap-2 px-1">
<p><%= Tag.untagged_name %></p>
</div>
+ <% elsif param_key == "reconcile_status" %>
+ <div class="flex items-center gap-2 px-1">
+ <%= icon(reconcile_status_icon(param_value), size: "sm") %>
+ <p><%= t("transactions.reconcile.statuses.#{param_value}") %></p>
+ </div>
<% elsif param_key == "categories" && param_value == Category::UNCATEGORIZED_FILTER_VALUE %>
<div class="flex items-center gap-2 px-1">
<p><%= Category.uncategorized_name %></p>
diff --git a/app/views/transactions/searches/filters/_reconcile_status_filter.html.erb b/app/views/transactions/searches/filters/_reconcile_status_filter.html.erb
new file mode 100644
index 0000000000..2d2761d9fd
--- /dev/null
+++ b/app/views/transactions/searches/filters/_reconcile_status_filter.html.erb
@@ -0,0 +1,17 @@
+<%# locals: (form:) %>
+
+<div class="p-2 space-y-3">
+ <% Entry.reconciled_statuses.keys.each do |status| %>
+ <div class="flex items-center gap-3" data-filter-name="<%= status %>">
+ <%= form.check_box :reconcile_status,
+ {
+ multiple: true,
+ checked: @q[:reconcile_status]&.include?(status),
+ class: "checkbox checkbox--light"
+ },
+ status,
+ nil %>
+ <%= form.label :reconcile_status, t("transactions.reconcile.statuses.#{status}"), value: status, class: "text-sm text-primary" %>
+ </div>
+ <% end %>
+</div>
diff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.yml
index debd1d32ad..c8ec78816d 100644
--- a/config/locales/views/accounts/en.yml
+++ b/config/locales/views/accounts/en.yml
@@ -5,6 +5,9 @@ en:
destroy:
success: "Entry deleted successfully."
accounts:
+ reconciliation_indicator:
+ matched: All transactions reconciled
+ needs_attention: Transactions need reconciliation
not_authorized: "You don't have permission to manage this account"
scheduled_balance_tooltip:
description: Your balance once all scheduled transactions have posted
diff --git a/config/locales/views/settings/preferences/en.yml b/config/locales/views/settings/preferences/en.yml
index 4060d0caca..84a9483a4d 100644
--- a/config/locales/views/settings/preferences/en.yml
+++ b/config/locales/views/settings/preferences/en.yml
@@ -8,6 +8,10 @@ en:
date_format: Date format
general_subtitle: Configure your preferences
general_title: General
+ transactions_title: Transactions
+ transactions_subtitle: Configure how transactions behave
+ manual_reconciliation: Manual reconciliation
+ manual_reconciliation_hint: Show reconcile controls on manually-entered accounts. Accounts with a bank sync use statement reconciliation instead.
default_period: Default Period
default_account_order: Default Account Order
default_account_order_hint: With Manual, drag accounts in the sidebar to set their order.
diff --git a/config/locales/views/transactions/de.yml b/config/locales/views/transactions/de.yml
index 77f5207d00..d3dc28253b 100644
--- a/config/locales/views/transactions/de.yml
+++ b/config/locales/views/transactions/de.yml
@@ -134,6 +134,18 @@ de:
dismiss_duplicate:
success: Als getrennte Transaktionen beibehalten
failure: Duplikatshinweis konnte nicht verworfen werden
+ reconcile:
+ success: Als %{status} markiert
+ failure: Abgleichsstatus konnte nicht aktualisiert werden
+ not_manual_account: Der Abgleichsstatus gilt nur für manuell erfasste Konten (kein Bank-Sync)
+ statuses:
+ unreconciled: Nicht abgeglichen
+ cleared: Bestätigt
+ reconciled: Abgeglichen
+ badge:
+ unreconciled_tooltip: "Noch nicht mit einem Kontoauszug abgeglichen. Klicken, um als bestätigt zu markieren."
+ cleared_tooltip: "Auf einem Kontoauszug bestätigt, aber noch nicht vollständig abgeglichen. Klicken, um als abgeglichen zu markieren."
+ reconciled_tooltip: "Abrechnungszeitraum vollständig abgeglichen. Klicken, um auf nicht abgeglichen zurückzusetzen."
header:
edit_categories: Kategorien bearbeiten
edit_imports: Importe bearbeiten
@@ -167,6 +179,7 @@ de:
date: Datum
type: Typ
status: Status
+ reconcile_status: Abgleich
amount: Betrag
category: Kategorie
tag: Tag
@@ -255,6 +268,7 @@ de:
clear_filters: Filter löschen
date_filter: Datum
merchant_filter: Händler
+ reconcile_status_filter: Abgleich
status_filter: Status
tag_filter: Tag
type_filter: Typ
@@ -295,10 +309,13 @@ de:
merchant_prompt: Händler wählen
name_label: Name
name_placeholder: Name, der für die gewählten Transaktionen gilt
+ no_change: (keine Änderung)
none: "(keine)"
notes_label: Notizen
notes_placeholder: Notiz, die für die gewählten Transaktionen gilt
overview: Übersicht
+ reconciled_status_hint: Gilt nur für manuell erfasste Konten (kein Bank-Sync).
+ reconciled_status_label: Abgleichsstatus
save: Speichern
tags_label: Tags
transactions_section: Transaktionen
@@ -347,6 +364,7 @@ de:
selection_bar:
duplicate: Duplizieren
edit: Bearbeiten
+ reconcile: Abgleichen
selected: ausgewählt
split_parent_row:
split_label: Teilen
diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.yml
index 4a63de96bc..488b18dd8c 100644
--- a/config/locales/views/transactions/en.yml
+++ b/config/locales/views/transactions/en.yml
@@ -12,10 +12,13 @@ en:
merchant_prompt: Select a merchant
name_label: Name
name_placeholder: Enter a name that will be applied to selected transactions
+ no_change: (no change)
none: "(none)"
notes_label: Notes
notes_placeholder: Enter a note that will be applied to selected transactions
overview: Overview
+ reconciled_status_hint: Only applies to manually-entered accounts (no bank sync).
+ reconciled_status_label: Reconciliation status
save: Save
tags_label: Tags
transactions_section: Transactions
@@ -23,6 +26,7 @@ en:
selection_bar:
duplicate: Duplicate
edit: Edit
+ reconcile: Reconcile
selected: selected
form:
details: Details
@@ -200,6 +204,19 @@ en:
dismiss_duplicate:
success: Kept as separate transactions
failure: Could not dismiss duplicate suggestion
+ reconcile:
+ success: Marked as %{status}
+ failure: Could not update reconciliation status
+ unavailable: Reconciliation is not enabled for this family
+ not_manual_account: Reconciliation status only applies to manually-entered accounts (no bank sync)
+ statuses:
+ unreconciled: Unreconciled
+ cleared: Cleared
+ reconciled: Reconciled
+ badge:
+ unreconciled_tooltip: "Not yet checked against a statement. Click to mark as cleared."
+ cleared_tooltip: "Confirmed on a statement, not yet fully reconciled. Click to mark as reconciled."
+ reconciled_tooltip: "Statement period fully reconciled. Click to reset to unreconciled."
pending_duplicate_merge:
possible_duplicate: Duplicate?
possible_duplicate_short: Dup?
@@ -282,6 +299,7 @@ en:
date: Date
type: Type
status: Status
+ reconcile_status: Reconciliation
amount: Amount
category: Category
tag: Tag
@@ -384,6 +402,7 @@ en:
clear_filters: Clear filters
date_filter: Date
merchant_filter: Merchant
+ reconcile_status_filter: Reconciliation
status_filter: Status
tag_filter: Tag
type_filter: Type
diff --git a/config/routes.rb b/config/routes.rb
index 680e86f141..40176a354b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -627,6 +627,7 @@ Rails.application.routes.draw do
post :merge_duplicate
post :dismiss_duplicate
post :unlock
+ patch :reconcile
patch :tags, action: :update_tags
end
end
diff --git a/db/migrate/20260805174227_add_manual_reconciliation.rb b/db/migrate/20260805174227_add_manual_reconciliation.rb
new file mode 100644
index 0000000000..325abb74dc
--- /dev/null
+++ b/db/migrate/20260805174227_add_manual_reconciliation.rb
@@ -0,0 +1,16 @@
+class AddManualReconciliation < ActiveRecord::Migration[8.1]
+ # Build the index without blocking writes to large entries tables.
+ disable_ddl_transaction!
+
+ def change
+ add_column :entries, :reconciled_status, :string, default: "unreconciled", null: false
+ add_index :entries, [ :account_id, :reconciled_status ],
+ name: "index_entries_on_account_id_and_reconciled_status",
+ algorithm: :concurrently
+ add_check_constraint :entries,
+ "reconciled_status IN ('unreconciled', 'cleared', 'reconciled')",
+ name: "chk_entries_reconciled_status"
+
+ add_column :families, :manual_reconciliation, :boolean, default: false, null: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 98021a1606..1031552662 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -723,6 +723,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_11_080000) do
t.string "name", null: false
t.text "notes"
t.uuid "parent_entry_id"
+ t.string "reconciled_status", default: "unreconciled", null: false
t.string "plaid_id"
t.datetime "reconciled_at"
t.uuid "reconciled_by_statement_id"
@@ -742,6 +743,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_11_080000) do
t.index ["import_id"], name: "index_entries_on_import_id"
t.index ["import_locked"], name: "index_entries_on_import_locked_true", where: "(import_locked = true)"
t.index ["parent_entry_id"], name: "index_entries_on_parent_entry_id"
+ t.index ["account_id", "reconciled_status"], name: "index_entries_on_account_id_and_reconciled_status"
+ t.check_constraint "reconciled_status::text = ANY (ARRAY['unreconciled'::character varying, 'cleared'::character varying, 'reconciled'::character varying]::text[])", name: "chk_entries_reconciled_status"
t.index ["reconciled_by_statement_id"], name: "index_entries_on_reconciled_by_statement", where: "(reconciled_by_statement_id IS NOT NULL)"
t.index ["user_modified"], name: "index_entries_on_user_modified_true", where: "(user_modified = true)"
t.check_constraint "reconciled_by_statement_id IS NULL OR reconciled_at IS NOT NULL", name: "chk_entries_reconciled_at_present_when_statement_set"
@@ -870,6 +873,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_11_080000) do
t.datetime "latest_sync_activity_at", default: -> { "CURRENT_TIMESTAMP" }
t.datetime "latest_sync_completed_at", default: -> { "CURRENT_TIMESTAMP" }
t.string "locale", default: "en"
+ t.boolean "manual_reconciliation", default: false, null: false
t.string "moniker", default: "Family", null: false
t.integer "month_start_day", default: 1, null: false
t.string "name"
diff --git a/test/components/DS/tooltip_test.rb b/test/components/DS/tooltip_test.rb
index ef801dd3ef..d1b18cf006 100644
--- a/test/components/DS/tooltip_test.rb
+++ b/test/components/DS/tooltip_test.rb
@@ -1,6 +1,17 @@
require "test_helper"
class DS::TooltipTest < ViewComponent::TestCase
+ test "uses custom trigger content when provided" do
+ trigger = '<span class="reconciliation-indicator"></span>'.html_safe
+
+ render_inline(DS::Tooltip.new(text: "Matched", as: :span, trigger_content: trigger))
+
+ assert_selector "span.reconciliation-indicator"
+ assert_no_selector "svg"
+ assert_selector "[aria-describedby^='tooltip-']"
+ assert_selector "[role='tooltip']", text: "Matched"
+ end
+
test "defaults to the inverse surface with an icon trigger" do
render_inline(DS::Tooltip.new(text: "Helpful hint"))
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index bbdb454e9e..6e67c5161e 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -17,6 +17,20 @@ 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
+
+ assert_response :success
+ assert_not_includes response.body, I18n.t("accounts.reconciliation_indicator.needs_attention")
+
+ @user.family.update!(manual_reconciliation: true)
+
+ get accounts_url
+
+ assert_response :success
+ assert_includes response.body, I18n.t("accounts.reconciliation_indicator.needs_attention")
+ end
+
test "show points an unmatched transaction with a counterpart to the transfer matcher" do
outflow = create_transaction(account: @account, name: "Hint outflow", amount: 500, date: Date.current)
create_transaction(account: accounts(:credit_card), name: "Hint inflow", amount: -500, date: Date.current)
diff --git a/test/controllers/settings/preferences_controller_test.rb b/test/controllers/settings/preferences_controller_test.rb
index a8938cd93a..d83e18b7ae 100644
--- a/test/controllers/settings/preferences_controller_test.rb
+++ b/test/controllers/settings/preferences_controller_test.rb
@@ -107,4 +107,33 @@ class Settings::PreferencesControllerTest < ActionDispatch::IntegrationTest
assert_not_includes response.body, I18n.t("settings.preferences.show.household_budget_enabled")
assert_not_includes response.body, I18n.t("settings.preferences.show.budget_sharing_title")
end
+
+ test "admins with preview access see the manual reconciliation toggle" do
+ user = users(:family_admin)
+ user.update!(preferences: (user.preferences || {}).merge("preview_features_enabled" => true))
+
+ get settings_preferences_url
+
+ assert_response :success
+ assert_select "input[name='user[family_attributes][manual_reconciliation]']"
+ assert_match I18n.t("settings.preferences.show.manual_reconciliation"), response.body
+ end
+
+ test "hides the manual reconciliation toggle without preview access" do
+ get settings_preferences_url
+
+ assert_response :success
+ assert_select "input[name='user[family_attributes][manual_reconciliation]']", count: 0
+ end
+
+ test "members with preview access do not see the manual reconciliation toggle" do
+ user = users(:family_member)
+ user.update!(preferences: (user.preferences || {}).merge("preview_features_enabled" => true))
+ sign_in user
+
+ get settings_preferences_url
+
+ assert_response :success
+ assert_select "input[name='user[family_attributes][manual_reconciliation]']", count: 0
+ end
end
diff --git a/test/controllers/transactions/bulk_updates_controller_test.rb b/test/controllers/transactions/bulk_updates_controller_test.rb
index 6e19d079e0..abc73abe74 100644
--- a/test/controllers/transactions/bulk_updates_controller_test.rb
+++ b/test/controllers/transactions/bulk_updates_controller_test.rb
@@ -139,6 +139,7 @@ class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
assert_equal [ new_tag.id ], transaction_entry.transaction.tag_ids
end
+
test "bulk update ignores category, merchant and tag ids from another family" do
other_family = families(:empty)
foreign_category = other_family.categories.create!(name: "Foreign category")
@@ -269,4 +270,92 @@ class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
assert_equal [ "Annotate", "bulk note" ], [ annotate_entry.reload.name, annotate_entry.notes ]
assert_equal [ "Private", nil ], [ private_entry.reload.name, private_entry.notes ]
end
+
+ test "bulk update sets reconciled_status on manual accounts" do
+ @user.family.update!(manual_reconciliation: true)
+ manual_entry = create_transaction(account: accounts(:depository))
+ assert accounts(:depository).manual?
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ manual_entry.id ],
+ reconciled_status: "reconciled"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ assert_equal "reconciled", manual_entry.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))
+ assert_not accounts(:connected).manual?
+
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ synced_entry.id ],
+ reconciled_status: "reconciled"
+ }
+ }
+
+ assert_redirected_to transactions_url
+ assert_equal "unreconciled", synced_entry.reload.reconciled_status
+ end
+
+ test "bulk update rejects an invalid reconciled_status value without raising" do
+ @user.family.update!(manual_reconciliation: true)
+ manual_entry = create_transaction(account: accounts(:depository))
+
+ assert_no_changes -> { manual_entry.reload.reconciled_status } do
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ manual_entry.id ],
+ reconciled_status: "not_a_real_status"
+ }
+ }
+ end
+
+ assert_redirected_to transactions_url
+ assert_equal I18n.t("transactions.reconcile.failure"), flash[:alert]
+ end
+
+ test "bulk update records a debug log entry when the update fails" do
+ manual_entry = create_transaction(account: accounts(:depository))
+ Entry.stubs(:bulk_update!).raises(ActiveRecord::RecordInvalid.new(manual_entry))
+
+ assert_difference -> { DebugLogEntry.where(category: "reconciliation", level: "error").count }, 1 do
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ manual_entry.id ],
+ notes: "Updated note"
+ }
+ }
+ end
+
+ assert_redirected_to transactions_url
+ assert_equal I18n.t("transactions.reconcile.failure"), flash[:alert]
+
+ log_entry = DebugLogEntry.order(:created_at).last
+ assert_equal "Transactions::BulkUpdatesController#create", log_entry.source
+ assert_equal @user.family, log_entry.family
+ assert_equal @user, log_entry.user
+ assert_equal [ manual_entry.id ], log_entry.metadata["entry_ids"]
+ end
+
+ test "bulk update rejects reconciled_status when manual reconciliation is disabled" do
+ manual_entry = create_transaction(account: accounts(:depository))
+
+ assert_no_changes -> { manual_entry.reload.reconciled_status } do
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ manual_entry.id ],
+ reconciled_status: "cleared"
+ }
+ }
+ end
+
+ assert_redirected_to transactions_url
+ assert_equal I18n.t("transactions.reconcile.unavailable"), flash[:alert]
+ end
end
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index f367071311..6a31c26a0f 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -1855,6 +1855,103 @@ end
"Expected transfer counterparty accounts to be preloaded"
end
+ test "reconcile is unavailable when manual reconciliation is disabled" do
+ manual_account = accounts(:depository)
+ entry = create_transaction(account: manual_account, amount: 50)
+
+ patch reconcile_transaction_path(entry.transaction)
+
+ assert_response :not_found
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "reconcile cycles through unreconciled -> cleared -> reconciled -> unreconciled on a manual account" do
+ @user.family.update!(manual_reconciliation: true)
+ manual_account = accounts(:depository)
+ assert manual_account.manual?, "fixture precondition: depository account must be manual"
+
+ entry = create_transaction(account: manual_account, amount: 50)
+ assert_equal "unreconciled", entry.reconciled_status
+
+ patch reconcile_transaction_path(entry.transaction)
+ assert_redirected_to transactions_path
+ assert_equal "cleared", entry.reload.reconciled_status
+ assert_equal "Marked as Cleared", flash[:notice]
+
+ patch reconcile_transaction_path(entry.transaction)
+ assert_equal "reconciled", entry.reload.reconciled_status
+
+ patch reconcile_transaction_path(entry.transaction)
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "reconcile records a debug log entry when the status update fails" do
+ @user.family.update!(manual_reconciliation: true)
+ manual_account = accounts(:depository)
+ entry = create_transaction(account: manual_account, amount: 50)
+ Entry.any_instance.stubs(:advance_reconciled_status!).raises(ActiveRecord::RecordInvalid.new(entry))
+
+ assert_difference -> { DebugLogEntry.where(category: "reconciliation", level: "error").count }, 1 do
+ patch reconcile_transaction_path(entry.transaction)
+ end
+
+ assert_redirected_to transactions_path
+ assert_equal I18n.t("transactions.reconcile.failure"), flash[:alert]
+ assert_equal "unreconciled", entry.reload.reconciled_status
+
+ log_entry = DebugLogEntry.order(:created_at).last
+ assert_equal "TransactionsController#reconcile", log_entry.source
+ assert_equal @user.family, log_entry.family
+ assert_equal @user, log_entry.user
+ assert_equal manual_account, log_entry.account
+ assert_equal entry.transaction.id.to_s, log_entry.metadata["transaction_id"]
+ assert_equal entry.id, log_entry.metadata["entry_id"]
+ end
+
+ test "reconcile is rejected for accounts with a live bank sync connection" do
+ @user.family.update!(manual_reconciliation: true)
+ linked_account = accounts(:connected)
+ assert_not linked_account.manual?, "fixture precondition: connected account must not be manual"
+
+ entry = create_transaction(account: linked_account, amount: 50)
+
+ patch reconcile_transaction_path(entry.transaction)
+
+ assert_redirected_to transactions_path
+ assert_equal "Reconciliation status only applies to manually-entered accounts (no bank sync)", flash[:alert]
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ # The badge used to render for any manual account, so a read_only share got a
+ # control the action refuses -- the click redirected back with an alert and
+ # the status never moved. Reconciling needs write access, not annotate access.
+ test "reconcile is rejected on a manual account shared with read-only access" do
+ @user.family.update!(manual_reconciliation: true)
+ read_only_account = accounts(:credit_card)
+ assert read_only_account.manual?, "fixture precondition: credit_card account must be manual"
+
+ entry = create_transaction(account: read_only_account, amount: 75)
+
+ sign_in users(:family_member)
+ patch reconcile_transaction_path(entry.transaction)
+
+ assert_redirected_to account_path(read_only_account)
+ assert_equal "You don't have permission to manage this account", flash[:alert]
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "reconcile is not accessible for another family's transaction" do
+ @user.family.update!(manual_reconciliation: true)
+ other_family = families(:empty)
+ other_account = other_family.accounts.create!(name: "Other family manual account", balance: 0, currency: "USD", accountable: Depository.new)
+ other_entry = create_transaction(account: other_account, amount: 25)
+
+ patch reconcile_transaction_path(other_entry.transaction)
+
+ assert_response :not_found
+ assert_equal "unreconciled", other_entry.reload.reconciled_status
+ end
+
test "index caches uncategorized_count and projected_recurring across requests" do
# Test environment uses null_store; swap in a memory store so the cache
# actually persists between the two requests below.
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
index 0a3b1aeb28..ea3b0c05ba 100644
--- a/test/controllers/users_controller_test.rb
+++ b/test/controllers/users_controller_test.rb
@@ -107,6 +107,32 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert @member.family.reload.investment_contributions_as_spending?
end
+ test "admin can enable manual reconciliation" do
+ patch user_url(@user), params: {
+ user: {
+ redirect_to: "preferences",
+ family_attributes: { id: @user.family.id, manual_reconciliation: "1" }
+ }
+ }
+
+ assert_redirected_to settings_preferences_url
+ assert @user.family.reload.manual_reconciliation?
+ end
+
+ test "non-admin cannot enable manual reconciliation" do
+ sign_in @member = users(:family_member)
+
+ patch user_url(@member), params: {
+ user: {
+ redirect_to: "preferences",
+ family_attributes: { id: @member.family.id, manual_reconciliation: "1" }
+ }
+ }
+
+ assert_redirected_to settings_profile_url
+ assert_not @member.family.reload.manual_reconciliation?
+ end
+
test "admin can reset family data" do
account = accounts(:investment)
category = categories(:income)
diff --git a/test/helpers/transactions_helper_test.rb b/test/helpers/transactions_helper_test.rb
index 4ece956bd1..e9c038fb21 100644
--- a/test/helpers/transactions_helper_test.rb
+++ b/test/helpers/transactions_helper_test.rb
@@ -8,6 +8,43 @@ class TransactionsHelperTest < ActionView::TestCase
OpenStruct.new(extra: extra)
end
+ test "reconcile filter is hidden unless manual reconciliation is enabled" do
+ Current.session = Session.create!(user: users(:family_admin))
+
+ assert_not_includes transaction_search_filters.map { |filter| filter[:key] }, "reconcile_status_filter"
+
+ Current.family.update!(manual_reconciliation: true)
+
+ assert_includes transaction_search_filters.map { |filter| filter[:key] }, "reconcile_status_filter"
+ end
+
+ test "can_reconcile_account? mirrors the write access the reconcile action requires" do
+ Current.session = Session.create!(user: users(:family_member))
+
+ assert can_reconcile_account?(accounts(:depository)),
+ "full_control share is write access"
+ assert_not can_reconcile_account?(accounts(:credit_card)),
+ "read_only share cannot reconcile"
+ assert_not can_reconcile_account?(accounts(:investment)),
+ "an account with no share at all cannot reconcile"
+ end
+
+ test "can_reconcile_account? lets the owner reconcile" do
+ Current.session = Session.create!(user: users(:family_admin))
+
+ assert can_reconcile_account?(accounts(:investment)), "owner can reconcile"
+ end
+
+ test "can_reconcile_account? does not treat annotate access as write access" do
+ share = account_shares(:credit_card_shared_with_member)
+ share.update!(permission: "read_write")
+
+ Current.session = Session.create!(user: users(:family_member))
+
+ assert_not can_reconcile_account?(accounts(:credit_card)),
+ "read_write is annotate access, and #reconcile requires write"
+ 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/account/reconciliation_indicator_test.rb b/test/models/account/reconciliation_indicator_test.rb
new file mode 100644
index 0000000000..a0e9effa70
--- /dev/null
+++ b/test/models/account/reconciliation_indicator_test.rb
@@ -0,0 +1,88 @@
+require "test_helper"
+
+class Account::ReconciliationIndicatorTest < ActiveSupport::TestCase
+ setup do
+ @account = families(:empty).accounts.create!(
+ name: "Reconciliation account",
+ balance: 0,
+ currency: "USD",
+ accountable: Depository.new
+ )
+ end
+
+ test "is matched when every transaction is reconciled" do
+ entry = @account.entries.create!(
+ name: "Reconciled transaction",
+ amount: 25,
+ currency: @account.currency,
+ date: Date.current,
+ entryable: Transaction.new
+ )
+ entry.update!(reconciled_status: "reconciled")
+
+ assert_equal :matched, Account::ReconciliationIndicator.for_accounts([ @account ])[@account.id]
+ end
+
+ test "is matched when the latest statement reconciles to the account balance" do
+ Account.stubs(:manual).returns(Account.where.not(id: @account.id))
+ period_end = Date.new(2026, 1, 31)
+ statement = AccountStatement.create_from_upload!(
+ family: @account.family,
+ account: @account,
+ file: uploaded_file(filename: "statement.csv", content_type: "text/csv", content: "date,amount\n2026-01-31,100\n")
+ )
+ statement.update!(period_start_on: Date.new(2026, 1, 1), period_end_on: period_end, closing_balance: 100)
+ @account.balances.create!(
+ date: period_end,
+ balance: 100,
+ currency: @account.currency,
+ cash_inflows: 100
+ )
+
+ assert_equal :matched, Account::ReconciliationIndicator.for_accounts([ @account ])[@account.id]
+ end
+
+ test "needs attention for an unreconciled transaction after a matched statement period" do
+ Account.stubs(:manual).returns(Account.where.not(id: @account.id))
+ period_end = Date.new(2026, 1, 31)
+ statement = AccountStatement.create_from_upload!(
+ family: @account.family,
+ account: @account,
+ file: uploaded_file(filename: "statement.csv", content_type: "text/csv", content: "date,amount\n2026-01-31,100\n")
+ )
+ statement.update!(period_start_on: Date.new(2026, 1, 1), period_end_on: period_end, closing_balance: 100)
+ @account.balances.create!(date: period_end, balance: 100, currency: @account.currency, cash_inflows: 100)
+ @account.entries.create!(
+ name: "February transaction",
+ amount: 25,
+ currency: @account.currency,
+ date: Date.new(2026, 2, 1),
+ entryable: Transaction.new
+ )
+
+ assert_equal :needs_attention, Account::ReconciliationIndicator.for_accounts([ @account ])[@account.id]
+ end
+
+ test "needs attention when a transaction is unreconciled" do
+ @account.entries.create!(
+ name: "Unreconciled transaction",
+ amount: 25,
+ currency: @account.currency,
+ date: Date.current,
+ entryable: Transaction.new
+ )
+
+ assert_equal :needs_attention, Account::ReconciliationIndicator.for_accounts([ @account ])[@account.id]
+ end
+
+ test "has no indicator without statements or transactions" do
+ account = families(:empty).accounts.create!(
+ name: "Empty account",
+ balance: 0,
+ currency: "USD",
+ accountable: Depository.new
+ )
+
+ assert_nil Account::ReconciliationIndicator.for_accounts([ account ])[account.id]
+ end
+end
diff --git a/test/models/entry_reconciliation_test.rb b/test/models/entry_reconciliation_test.rb
index 083d72f2ea..949496baa6 100644
--- a/test/models/entry_reconciliation_test.rb
+++ b/test/models/entry_reconciliation_test.rb
@@ -12,8 +12,8 @@ class EntryReconciliationTest < ActiveSupport::TestCase
entry = create_transaction(account: @account)
assert_equal :uncleared, entry.reconciliation_state
- assert_not entry.cleared?
- assert_not entry.reconciled?
+ assert_not entry.statement_cleared?
+ assert_not entry.statement_reconciled?
end
test "an entry carrying provider provenance is cleared without storing a flag" do
@@ -46,7 +46,7 @@ class EntryReconciliationTest < ActiveSupport::TestCase
entry = create_transaction(account: @account)
entry.mark_reconciled!
- assert entry.reload.reconciled?
+ assert entry.reload.statement_reconciled?
assert_nil entry.reconciled_by_statement_id
end
@@ -65,10 +65,10 @@ class EntryReconciliationTest < ActiveSupport::TestCase
unreconciled = create_transaction(account: @account)
reconciled.mark_reconciled!(statement: @statement)
- assert_includes Entry.reconciled, reconciled
- assert_not_includes Entry.reconciled, unreconciled
- assert_includes Entry.unreconciled, unreconciled
- assert_includes Entry.reconciled_by(@statement), reconciled
+ assert_includes Entry.statement_reconciled, reconciled
+ assert_not_includes Entry.statement_reconciled, unreconciled
+ assert_includes Entry.statement_unreconciled, unreconciled
+ assert_includes Entry.reconciled_by_statement(@statement), reconciled
end
test "deleting the statement leaves the entry reconciled but unevidenced" do
@@ -78,7 +78,7 @@ class EntryReconciliationTest < ActiveSupport::TestCase
@statement.destroy!
entry.reload
- assert entry.reconciled?, "reconciliation should survive losing the evidence"
+ assert entry.statement_reconciled?, "reconciliation should survive losing the evidence"
assert_nil entry.reconciled_by_statement_id
end
diff --git a/test/models/entry_test.rb b/test/models/entry_test.rb
index 88e4dcdcb8..d4f1a2854e 100644
--- a/test/models/entry_test.rb
+++ b/test/models/entry_test.rb
@@ -58,6 +58,110 @@ class EntryTest < ActiveSupport::TestCase
assert_not_nil category.reload.last_used_at
end
+ test "reconciled_status defaults to unreconciled" do
+ entry = create_transaction(account: accounts(:depository))
+
+ assert entry.unreconciled?
+ assert_equal "unreconciled", entry.reconciled_status
+ end
+
+ test "advance_reconciled_status! cycles unreconciled -> cleared -> reconciled -> unreconciled" do
+ entry = create_transaction(account: accounts(:depository))
+
+ entry.advance_reconciled_status!
+ assert_equal "cleared", entry.reload.reconciled_status
+
+ entry.advance_reconciled_status!
+ assert_equal "reconciled", entry.reload.reconciled_status
+
+ entry.advance_reconciled_status!
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ end
+
+ test "needs_reconciliation scope includes unreconciled and cleared, excludes reconciled" do
+ account = accounts(:depository)
+ unreconciled = create_transaction(account: account, name: "Unreconciled")
+ cleared = create_transaction(account: account, name: "Cleared")
+ reconciled = create_transaction(account: account, name: "Reconciled")
+
+ cleared.update!(reconciled_status: "cleared")
+ reconciled.update!(reconciled_status: "reconciled")
+
+ scoped_ids = Entry.where(id: [ unreconciled.id, cleared.id, reconciled.id ]).needs_reconciliation.pluck(:id)
+
+ assert_includes scoped_ids, unreconciled.id
+ assert_includes scoped_ids, cleared.id
+ assert_not_includes scoped_ids, reconciled.id
+ end
+
+ test "cleared_or_reconciled scope includes cleared and reconciled, excludes unreconciled" do
+ account = accounts(:depository)
+ unreconciled = create_transaction(account: account, name: "Unreconciled")
+ cleared = create_transaction(account: account, name: "Cleared")
+ reconciled = create_transaction(account: account, name: "Reconciled")
+
+ cleared.update!(reconciled_status: "cleared")
+ reconciled.update!(reconciled_status: "reconciled")
+
+ scoped_ids = Entry.where(id: [ unreconciled.id, cleared.id, reconciled.id ]).cleared_or_reconciled.pluck(:id)
+
+ assert_not_includes scoped_ids, unreconciled.id
+ assert_includes scoped_ids, cleared.id
+ assert_includes scoped_ids, reconciled.id
+ end
+
+ test "bulk_update! applies reconciled_status to manual accounts" do
+ entry = create_transaction(account: accounts(:depository))
+ assert accounts(:depository).manual?
+
+ Entry.where(id: entry.id).bulk_update!({ reconciled_status: "cleared" })
+
+ assert_equal "cleared", entry.reload.reconciled_status
+ end
+
+ test "bulk_update! ignores reconciled_status for synced accounts" do
+ entry = create_transaction(account: accounts(:connected))
+ assert_not accounts(:connected).manual?
+
+ Entry.where(id: entry.id).bulk_update!({ reconciled_status: "cleared" })
+
+ assert_equal "unreconciled", entry.reload.reconciled_status
+ 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))
+
+ updated_count = Entry.where(id: [ manual_entry.id, synced_entry.id ])
+ .bulk_update!({ reconciled_status: "cleared" })
+
+ assert_equal "cleared", manual_entry.reload.reconciled_status
+ assert_equal "unreconciled", synced_entry.reload.reconciled_status
+ assert_equal 1, updated_count, "only the manual entry actually changed, so the reported count should be 1, not 2"
+ assert_not synced_entry.user_modified?
+ end
+
+ test "bulk_update! reconciling alone does not lock saved attributes, matching advance_reconciled_status!" do
+ entry = create_transaction(account: accounts(:depository), category: categories(:food_and_drink))
+
+ Entry.where(id: entry.id).bulk_update!({ reconciled_status: "cleared" })
+ entry.reload
+
+ assert_equal "cleared", entry.reconciled_status
+ assert_not entry.user_modified?, "reconciling alone shouldn't lock the entry from future auto-categorization, same as clicking the badge does"
+ end
+
+ test "bulk_update! locks saved attributes when reconciled_status is combined with a real edit" do
+ entry = create_transaction(account: accounts(:depository))
+
+ Entry.where(id: entry.id).bulk_update!({ reconciled_status: "cleared", notes: "verified against statement" })
+ entry.reload
+
+ assert_equal "cleared", entry.reconciled_status
+ assert_equal "verified against statement", entry.notes
+ assert entry.user_modified?, "a real edit alongside reconciliation should still lock as before"
+ end
+
test "bulk_update! syncs each account once and schedules the catch-up job when dates move into the future" do
account = accounts(:depository)
entries = [ create_transaction(account: account), create_transaction(account: account) ]
diff --git a/test/models/pdf_import_reconciliation_test.rb b/test/models/pdf_import_reconciliation_test.rb
index 58783a6b47..5c44f87aa9 100644
--- a/test/models/pdf_import_reconciliation_test.rb
+++ b/test/models/pdf_import_reconciliation_test.rb
@@ -126,7 +126,7 @@ class PdfImportReconciliationTest < ActiveSupport::TestCase
@import.assign_account!(other)
- assert_not on_first.reload.reconciled?, "the old account's entry is no longer evidence-backed"
+ assert_not on_first.reload.statement_reconciled?, "the old account's entry is no longer evidence-backed"
assert_equal 1, @import.reload.rows_count, "nothing on the new account matches, so it is offered"
end
@@ -231,18 +231,18 @@ class PdfImportReconciliationTest < ActiveSupport::TestCase
on_first = create_transaction(account: @account, date: @date, amount: 50, name: "Coffee")
@import.update!(extracted_data: { "transactions" => [ extracted(date: @date, amount: -50, name: "Coffee") ] })
@import.generate_rows_from_extracted_data
- assert on_first.reload.reconciled?
+ assert on_first.reload.statement_reconciled?
@import.assign_account!(other)
# Both fields matter: reconciled_at is the state, reconciled_by_statement_id
# is the evidence, and Entry#unmark_reconciled! clears the pair.
on_first.reload
- assert_not on_first.reconciled?, "the account being left is released"
+ assert_not on_first.statement_reconciled?, "the account being left is released"
assert_nil on_first.reconciled_by_statement_id, "its statement evidence is cleared too"
on_other.reload
- assert on_other.reconciled?, "another account's evidence must survive"
+ assert on_other.statement_reconciled?, "another account's evidence must survive"
assert_equal @statement.id, on_other.reconciled_by_statement_id
end
@@ -285,7 +285,7 @@ class PdfImportReconciliationTest < ActiveSupport::TestCase
drifted = create_transaction(account: @account, date: @date, amount: 50, name: "Coffee")
@import.update!(extracted_data: { "transactions" => [ extracted(date: @date, amount: -50, name: "Coffee") ] })
@import.generate_rows_from_extracted_data
- assert drifted.reload.reconciled?
+ assert drifted.reload.statement_reconciled?
@import.update!(status: :complete)
# Corrected after the fact, so the statement line no longer describes it.
@@ -294,7 +294,7 @@ class PdfImportReconciliationTest < ActiveSupport::TestCase
@import.revert
drifted.reload
- assert_not drifted.reconciled?, "a statement that no longer matches must stop claiming the entry"
+ assert_not drifted.statement_reconciled?, "a statement that no longer matches must stop claiming the entry"
assert_nil drifted.reconciled_by_statement_id
assert_equal 1, @import.reload.rows_count
assert @import.pending?, "expected pending, got #{@import.status}"
diff --git a/test/models/transaction/search_test.rb b/test/models/transaction/search_test.rb
index a2406b7328..6f4a749021 100644
--- a/test/models/transaction/search_test.rb
+++ b/test/models/transaction/search_test.rb
@@ -1014,6 +1014,47 @@ class Transaction::SearchTest < ActiveSupport::TestCase
assert_not_includes pending_ids, confirmed.entryable.id
end
+ test "reconcile_status filter matches the selected manual reconciliation statuses" do
+ unreconciled = create_transaction(account: @checking_account, amount: 100, kind: "standard")
+ cleared = create_transaction(account: @checking_account, amount: 100, kind: "standard")
+ reconciled = create_transaction(account: @checking_account, amount: 100, kind: "standard")
+
+ cleared.update!(reconciled_status: "cleared")
+ reconciled.update!(reconciled_status: "reconciled")
+
+ cleared_ids = Transaction::Search.new(@family, filters: { reconcile_status: [ "cleared" ] }).transactions_scope.pluck(:id)
+ assert_includes cleared_ids, cleared.entryable.id
+ assert_not_includes cleared_ids, unreconciled.entryable.id
+ assert_not_includes cleared_ids, reconciled.entryable.id
+
+ cleared_or_reconciled_ids = Transaction::Search.new(@family, filters: { reconcile_status: [ "cleared", "reconciled" ] }).transactions_scope.pluck(:id)
+ assert_includes cleared_or_reconciled_ids, cleared.entryable.id
+ assert_includes cleared_or_reconciled_ids, reconciled.entryable.id
+ assert_not_includes cleared_or_reconciled_ids, unreconciled.entryable.id
+ end
+
+ test "reconcile_status filter is a no-op when blank" do
+ entry = create_transaction(account: @checking_account, amount: 100, kind: "standard")
+
+ ids = Transaction::Search.new(@family, filters: { reconcile_status: [] }).transactions_scope.pluck(:id)
+
+ assert_includes ids, entry.entryable.id
+ end
+
+ test "reconcile_status filter excludes synced accounts even though they default to unreconciled" do
+ manual_entry = create_transaction(account: @checking_account, amount: 100, kind: "standard")
+ synced_account = accounts(:connected)
+ synced_entry = create_transaction(account: synced_account, amount: 100, kind: "standard")
+
+ assert_equal "unreconciled", manual_entry.reconciled_status
+ assert_equal "unreconciled", synced_entry.reconciled_status
+
+ ids = Transaction::Search.new(@family, filters: { reconcile_status: [ "unreconciled" ] }).transactions_scope.pluck(:id)
+
+ assert_includes ids, manual_entry.entryable.id
+ assert_not_includes ids, synced_entry.entryable.id
+ end
+
# Regression for https://github.com/we-promise/sure/issues/3174
# The summary box (COUNT / SUM) on the Transactions page inflated when a
# transaction was tagged with multiple of the filtered tags, because the