Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Give every bill row one date rail and one subline order (#3955)

Guillem Arias Fauste96bbae184dc4
diff --git a/app/controllers/bills_controller.rb b/app/controllers/bills_controller.rb
index 770a1e7e7d..6957865e47 100644
--- a/app/controllers/bills_controller.rb
+++ b/app/controllers/bills_controller.rb
@@ -62,20 +62,20 @@ class BillsController < ApplicationController
active_open, @dormant = open_occurrences.partition { |occurrence| occurrence.recurring_transaction.active? }
@overdue, upcoming = active_open.partition { |occurrence| occurrence.derived_state == :overdue }
- this_month, later = upcoming.partition { |occurrence| occurrence.due_on <= month_end }
- @this_month = this_month.sort_by(&:due_on)
- @overdue = @overdue.sort_by(&:due_on)
- @dormant = @dormant.sort_by(&:due_on)
+ # Snooze-aware, like the rail (bills_row_date): rows list in rail order,
+ # and a bill snoozed past the month's end belongs after it.
+ @this_month, later = upcoming.partition { |occurrence| occurrence.effective_due_on <= month_end }
+ @overdue = @overdue.sort_by(&:effective_due_on)
+ @dormant = @dormant.sort_by(&:effective_due_on)
# Beyond this month, one row per series: a weekly bill's next six
# occurrences are not six separate things to think about yet.
@later = later.group_by(&:recurring_transaction_id)
.values
- .map { |group| group.min_by(&:due_on) }
- .sort_by(&:due_on)
+ .map { |group| group.min_by(&:effective_due_on) }
+ .sort_by(&:effective_due_on)
@paid_this_month = closed.select { |occurrence| occurrence.paid? && occurrence.due_on >= today.beginning_of_month }
- .sort_by(&:due_on)
compute_kpis(today, month_end)
@@ -96,7 +96,7 @@ class BillsController < ApplicationController
# The month as one chronological list, paid rows in place under a check.
# Overdue rows are excluded: they get their own section.
- @month_rows = (@this_month + @paid_this_month).sort_by(&:due_on)
+ @month_rows = (@this_month + @paid_this_month).sort_by(&:effective_due_on)
# Next up filters on the DATE, not derived_state: a bill two days late is
# still :due within its grace period, and nothing already past its due date
@@ -449,12 +449,13 @@ class BillsController < ApplicationController
def payable_occurrences
# Price changes ride along because bills_attention_reason asks every
- # row whether its amount changed recently.
+ # row whether its amount changed recently, and recurrence rules because
+ # every row's subline names its schedule.
Current.family.recurring_occurrences
.where(recurring_transaction_id: payable_series_ids)
.where("due_on >= ? OR status = 'scheduled'", Date.current.beginning_of_month)
.where("due_on <= ?", Date.current + 90)
- .includes(recurring_transaction: [ :merchant, :recurring_price_changes ])
+ .includes(recurring_transaction: [ :merchant, :recurring_price_changes, :recurrence_rules ])
.to_a
end
@@ -505,29 +506,18 @@ class BillsController < ApplicationController
# the same news. Notices used to sort by date ascending, which put the
# oldest and smallest first and buried the one thing you could still act on.
TRIAL_URGENT_DAYS = 3
- MATERIAL_PRICE_SHIFT = 0.10
Notice = Data.define(:kind, :series, :date, :detail) do
def urgent?
case kind
when :trial then date <= Date.current + TRIAL_URGENT_DAYS
- when :price then price_shift >= MATERIAL_PRICE_SHIFT
+ when :price then detail.material?
else false
end
end
- # How far a price moved, as a fraction of what it was. A dollar on a
- # ten-dollar subscription is worth saying; a dollar on the rent is not.
- def price_shift
- return 0 unless kind == :price && detail&.previous_amount.to_d.positive?
-
- ((detail.new_amount - detail.previous_amount).abs / detail.previous_amount).to_f
- end
-
def price_percent
- return 0 unless kind == :price && detail&.previous_amount.to_d.positive?
-
- ((detail.new_amount - detail.previous_amount) / detail.previous_amount * 100).round
+ kind == :price ? (detail.shift * 100).round : 0
end
# Nearness to today in either direction: a change three days ago and a
diff --git a/app/helpers/bills_helper.rb b/app/helpers/bills_helper.rb
index 4f131a6b19..7cd0a04f6b 100644
--- a/app/helpers/bills_helper.rb
+++ b/app/helpers/bills_helper.rb
@@ -7,10 +7,12 @@ module BillsHelper
l(date, format: date.year == Date.current.year ? :short : :short_with_year)
end
- # The date a row in a dated section is about, as its date rail prints it and
- # as its subline leads with where the rail is hidden.
+ # The date a bill row is about. The subline leads with it below @lg, and the
+ # rail prints it from there up (bills_rail_date). Snooze-aware, like
+ # derived_state and Next up.
def bills_row_date(occurrence)
- occurrence.due_on == Date.current ? t("bills.row_today") : bills_upcoming_date(occurrence.due_on)
+ date = occurrence.effective_due_on
+ date == Date.current ? t("bills.row_today") : bills_upcoming_date(date)
end
# One-shot AI features (smart-fill, smart-configure) need both the user's
@@ -21,31 +23,23 @@ module BillsHelper
Current.user&.ai_enabled? && Provider::Registry.preferred_llm_provider.present?
end
- # Two bills can be genuinely indistinguishable on a row -- same merchant,
- # same amount, three tiers of one subscription. The keys returned here mark
- # exactly those collisions, so only the rows that need a second fact get one.
- def bills_ambiguous_row_keys(occurrences)
- occurrences.group_by { |o| [ o.recurring_transaction.display_name, o.resolved_expected_amount ] }
- .select { |_, group| group.size > 1 }
- .keys.to_set
- end
-
# Pay-period markers keyed by the id of the FIRST occurrence inside each
# period, so the section template can drop a marker between groups without
# pre-bucketing the rows. Each marker carries its period and the summed
- # obligations due inside it.
+ # obligations due inside it. Dated like the rail, so a snoozed row counts
+ # toward the period it sits in.
def bills_pay_period_markers(occurrences, pay_periods)
return {} if pay_periods.blank?
seen = Set.new
occurrences.each_with_object({}) do |occurrence, markers|
- index = pay_periods.index { |p| occurrence.due_on.between?(p.starts_on, p.ends_on) }
+ index = pay_periods.index { |p| occurrence.effective_due_on.between?(p.starts_on, p.ends_on) }
next unless index && seen.add?(index)
period = pay_periods[index]
markers[occurrence.id] = {
period: period,
- due_total: occurrences.select { |o| o.due_on.between?(period.starts_on, period.ends_on) }
+ due_total: occurrences.select { |o| o.effective_due_on.between?(period.starts_on, period.ends_on) }
.sum { |o| o.resolved_expected_amount.abs }
}
end
@@ -231,18 +225,17 @@ module BillsHelper
# drawer names the account regardless, so nothing is lost when it is quiet
# here.
def bills_paid_from_label(bill)
- return "" if bill.account.blank?
- return "" unless bills_span_multiple_accounts?
+ return if bill.account.blank?
+ return unless bills_span_multiple_accounts?
- " · #{t('bills.paid_from', account: bill.account.name)}"
+ t("bills.paid_from", account: bill.account.name)
end
# Autopay is a state, not a task, so it reads on the bill's own line rather
- # than in the slot where the row keeps its verb.
+ # than in the slot where the row keeps its verb. A paused bill isn't
+ # charging, so it doesn't claim autopay.
def bills_autopay_label(bill)
- return "" unless bill.autopay?
-
- " · #{t('recurring_transactions.pay_action.autopay')}"
+ t("recurring_transactions.pay_action.autopay") if bill.autopay? && bill.active?
end
# Memoized so this costs one query per request rather than one per row.
@@ -266,6 +259,13 @@ module BillsHelper
# closed the only useful fact left is when it had been due.
return t("bills.due_label.settled", date: date) unless occurrence.scheduled?
+ # Nobody is paying a bill that isn't active, so its leftover isn't late.
+ # The label leads with the bill's status instead, as its page does.
+ series = occurrence.recurring_transaction
+ unless series.active?
+ return safe_join([ t("recurring_transactions.status.#{series.status}"), t("bills.due_label.due_since", date: date) ], " · ")
+ end
+
# Overdue is the occurrence's own judgement, not a sign test on the date.
# RecurringOccurrence#derived_state only calls a cycle overdue once its
# grace period has run out, and every other surface honours that: the
@@ -302,25 +302,66 @@ module BillsHelper
end
end
- # Why this row is in the Needs attention section.
+ # Why this row needs a look, if it does.
#
- # The section used to say "Overdue" against every row, which is alarming
+ # Needs attention used to say "Overdue" against every row, which is alarming
# without being actionable: it names the symptom every row already shares
# instead of the thing that differs. First true wins, most specific first.
+ # Paused leads: nobody is paying that bill, so nothing after it applies.
+ # Partial stays bare, because the amount column already says what's left.
+ # Only Overdue is red. A late bill with a match to review or a partial
+ # payment gives that reason instead, uncoloured: in red it read as the
+ # problem itself. The row's date still says the bill is late.
def bills_attention_reason(occurrence, suggestion: nil)
+ series = occurrence.recurring_transaction
+ return t("bills.attention.paused") unless series.active?
return t("bills.attention.needs_review") if suggestion.present?
+ return t("bills.attention.partial") if occurrence.partially_paid?
- if occurrence.partially_paid?
- return t("bills.attention.partial", amount: format_money(occurrence.remaining_amount_money))
+ if occurrence.overdue?
+ days = (Date.current - occurrence.effective_due_on).to_i
+ return tag.span(t("bills.attention.overdue", count: days), class: "text-destructive")
end
- if occurrence.recurring_transaction.recurring_price_changes.any? { |change| change.effective_on >= 30.days.ago.to_date }
- return t("bills.attention.amount_changed")
- end
+ recently_changed = series.recurring_price_changes.any? { |change| change.effective_on >= 30.days.ago.to_date && change.material? }
+ t("bills.attention.amount_changed") if recently_changed
+ end
+
+ # A paused or dismissed bill's leftover is past its date, but nobody is
+ # paying it, so it isn't late: no red on its row, its drawers or its page.
+ def bills_overdue?(occurrence)
+ occurrence.recurring_transaction.active? && occurrence.overdue?
+ end
+
+ # A bill row's one line of context, in the same order in every section. It
+ # truncates from the end, so the facts you can most do without come last.
+ def bills_row_subline(occurrence, suggestion: nil)
+ series = occurrence.recurring_transaction
+
+ safe_join([
+ bills_autopay_label(series),
+ bills_attention_reason(occurrence, suggestion: suggestion),
+ bills_installment_progress(series),
+ (t("bills.debt_payment") if series.transfer?),
+ frequency_label(series),
+ bills_paid_from_label(series)
+ ].compact_blank, " · ")
+ end
+
+ # The payment the plan is on, capped at its last: a plan settled in full
+ # still lists its final row this month.
+ def bills_installment_progress(series)
+ done, total = series.installment_progress
+ t("bills.installment_progress", done_plus_one: [ done + 1, total ].min, total: total) if total
+ end
- return nil unless occurrence.derived_state == :overdue
+ # The rail is 56px wide, too narrow for "Jan 03, 2027", which wrapped
+ # mid-date. Another year's date puts the year on a line of its own.
+ def bills_rail_date(occurrence)
+ date = occurrence.effective_due_on
+ return bills_row_date(occurrence) if date.year == Date.current.year
- t("bills.attention.overdue", count: (Date.current - occurrence.effective_due_on).to_i)
+ safe_join([ l(date, format: :short), tag.span(date.year, class: "block text-subdued") ])
end
# The icons for the verbs below. Pay renders as the portal link instead
diff --git a/app/models/recurring_price_change.rb b/app/models/recurring_price_change.rb
index 03afd31f96..66fbd83d1e 100644
--- a/app/models/recurring_price_change.rb
+++ b/app/models/recurring_price_change.rb
@@ -13,4 +13,17 @@ class RecurringPriceChange < ApplicationRecord
enum :source, { detected: "detected", user: "user" }, prefix: :recorded_by
validates :effective_on, :previous_amount, :new_amount, :currency, presence: true
+
+ # A tenth either way is worth a top notice and a word on the bill's row. A
+ # dollar on a ten-dollar subscription is news; a dollar on the rent is not.
+ MATERIAL_SHIFT = BigDecimal("0.10")
+
+ # How far the price moved, as a signed fraction of what it was.
+ def shift
+ previous_amount.to_d.positive? ? (new_amount - previous_amount) / previous_amount : 0
+ end
+
+ def material?
+ shift.abs >= MATERIAL_SHIFT
+ end
end
diff --git a/app/views/bills/_occurrence.html.erb b/app/views/bills/_occurrence.html.erb
index f944500eb4..a371ddc970 100644
--- a/app/views/bills/_occurrence.html.erb
+++ b/app/views/bills/_occurrence.html.erb
@@ -1,4 +1,4 @@
-<%# locals: (occurrence:, date_label: false, suggestion: nil, disambiguate: false) %>
+<%# locals: (occurrence:, suggestion: nil) %>
<% series = occurrence.recurring_transaction %>
<% expected = occurrence.resolved_expected_amount_money %>
<% paid = occurrence.confirmed_allocated_money %>
@@ -29,12 +29,12 @@
piece of temporal context saying the same word twice. The colour still
carries the state; the rail now carries the date the state is about.
- Only from @lg. Below it the subline leads with the same date. %>
- <% if date_label %>
- <div class="hidden @lg:block w-14 shrink-0 text-xs <%= occurrence.derived_state == :overdue ? "text-destructive font-medium" : "text-secondary" %>">
- <%= bills_row_date(occurrence) %>
- </div>
- <% end %>
+ Every section has it, so the avatars line up down the stacked card.
+ Only from @lg. Below it the subline leads with the same date, in the
+ same colour. %>
+ <div class="hidden @lg:block w-14 shrink-0 text-xs <%= bills_overdue?(occurrence) ? "text-destructive font-medium" : "text-secondary" %>">
+ <%= bills_rail_date(occurrence) %>
+ </div>
<% if series.merchant&.logo_url.present? %>
<%= image_tag Setting.transform_brand_fetch_url(series.merchant.logo_url),
@@ -49,37 +49,16 @@
) %>
<% end %>
- <% reason = date_label ? bills_attention_reason(occurrence, suggestion: suggestion) : nil %>
<div class="min-w-0 flex-1">
<p class="<%= lead_tone %> text-sm font-medium truncate group-hover:underline">
<%= series.display_name %>
- <% if series.transfer? %>
- <span class="text-xs text-secondary font-normal"><%= t("bills.debt_payment") %></span>
- <% end %>
</p>
- <%# In a dated section the subline says WHY this row needs attention,
- which is the whole point of pulling those rows out of the run. %>
- <p class="text-xs truncate <%= reason && occurrence.derived_state == :overdue ? "text-destructive" : "text-secondary" %>">
- <% if date_label %>
- <span class="@lg:hidden"><%= bills_row_date(occurrence) %> &middot;</span>
- <% end %>
- <% if reason %>
- <%= reason %>
- <%# Two rows reading the same name and the same amount need telling
- apart, and the schedule is what actually differs between
- subscription tiers. %>
- <% if disambiguate %>
- <span class="text-secondary">&middot; <%= frequency_label(series) %></span>
- <% end %>
- <% else %>
- <%= date_label ? frequency_label(series) : occurrence_due_label(occurrence) %><%= bills_paid_from_label(series) %><%= bills_autopay_label(series) %>
- <% if disambiguate && !date_label %>
- &middot; <%= frequency_label(series) %>
- <% end %>
- <% end %>
- <% if (progress = series.installment_progress) %>
- &middot; <%= t("bills.installment_progress", done_plus_one: progress.first + 1, total: progress.last) %>
- <% end %>
+ <%# Says WHY this row needs a look, when it does, among the bill's other
+ facts. The schedule is always on it, which is also what tells
+ subscription tiers with one name and one amount apart. %>
+ <p class="text-xs text-secondary truncate">
+ <span class="@lg:hidden <%= "text-destructive" if bills_overdue?(occurrence) %>"><%= bills_row_date(occurrence) %> &middot;</span>
+ <%= bills_row_subline(occurrence, suggestion: suggestion) %>
</p>
<% if series.notes.present? %>
<p class="text-xs text-secondary truncate"><%= series.notes %></p>
@@ -102,19 +81,14 @@
<% if occurrence.paid? %>
<p class="text-xs text-success"><%= occurrence.overpaid? ? t("bills.paid_over_short") : t("bills.paid_label") %></p>
<% elsif occurrence.partially_paid? %>
- <%# Only when the left-hand subline has not already said it. In a dated
- section the attention reason reads "Partial · $1,612.50 remaining",
- and printing the same arithmetic again on the right is what was
+ <%# The subline says Partial and stops there. It used to add "$1,612.50
+ remaining", the same arithmetic printed twice, and that was
squeezing the bill's name out of the row. %>
- <% if reason.present? %>
- <p class="text-xs text-secondary"><%= t("bills.remaining_label") %></p>
- <% else %>
- <p class="text-xs text-secondary privacy-sensitive truncate">
- <%= t("bills.partial_progress", paid: format_money(paid), expected: format_money(expected)) %>
- </p>
- <% end %>
+ <p class="text-xs text-secondary"><%= t("bills.remaining_label") %></p>
<% elsif occurrence_amount_estimated?(occurrence) && series.has_amount_variance? %>
- <p class="text-xs text-secondary privacy-sensitive">
+ <%# Only from @lg: on a phone the range squeezed the name to "PG&E
+ Ele…". The ~ already says estimate, and the drawer has the range. %>
+ <p class="hidden @lg:block text-xs text-secondary privacy-sensitive">
<%= t("bills.amount_range",
min: format_money(series.expected_amount_min_money),
max: format_money(series.expected_amount_max_money)) %>
diff --git a/app/views/bills/_occurrence_section.html.erb b/app/views/bills/_occurrence_section.html.erb
index 978e67259d..edc46f0f70 100644
--- a/app/views/bills/_occurrence_section.html.erb
+++ b/app/views/bills/_occurrence_section.html.erb
@@ -1,11 +1,6 @@
-<%# locals: (title:, occurrences:, tone: :default, date_labels: false, suggestions: {}, meta: nil, pay_periods: []) %>
+<%# locals: (title:, occurrences:, tone: :default, suggestions: {}, meta: nil, pay_periods: []) %>
<% return if occurrences.empty? %>
-<%# Where two rows would read identically, and only there, the row earns a
- second fact to tell them apart (BillsHelper#bills_ambiguous_row_keys).
- Adding the schedule to every row instead would be nineteen copies of
- something nobody was confused about. %>
-<% ambiguous = bills_ambiguous_row_keys(occurrences) %>
<% markers = bills_pay_period_markers(occurrences, pay_periods) %>
<div>
@@ -36,11 +31,7 @@
currency: Current.family.currency,
due_total: marker[:due_total] %>
<% end %>
- <%= render "bills/occurrence",
- occurrence: occurrence,
- date_label: date_labels,
- suggestion: suggestions[occurrence.id],
- disambiguate: ambiguous.include?([ occurrence.recurring_transaction.display_name, occurrence.resolved_expected_amount ]) %>
+ <%= render "bills/occurrence", occurrence: occurrence, suggestion: suggestions[occurrence.id] %>
<% end %>
</div>
</div>
diff --git a/app/views/bills/_summary.html.erb b/app/views/bills/_summary.html.erb
index 002fdbb1e2..25a9d40033 100644
--- a/app/views/bills/_summary.html.erb
+++ b/app/views/bills/_summary.html.erb
@@ -24,10 +24,19 @@
<%= t("bills.summary.remaining", amount: format_money(current_occurrence.remaining_amount_money)) %>
<% end %>
</p>
- <p class="text-xs <%= current_occurrence.overdue? ? "text-destructive" : "text-secondary" %>">
+ <p class="text-xs <%= bills_overdue?(current_occurrence) ? "text-destructive" : "text-secondary" %>">
<span class="privacy-sensitive"><%= t("bills.partial_progress", paid: format_money(paid), expected: format_money(expected)) %></span>
&middot; <%= occurrence_due_label(current_occurrence) %>
</p>
+ <%# The row shows the range only from @lg, so on a phone this is where
+ an estimate says how far it can swing. %>
+ <% if occurrence_amount_estimated?(current_occurrence) && series.has_amount_variance? %>
+ <p class="text-xs text-secondary privacy-sensitive">
+ <%= t("bills.amount_range",
+ min: format_money(series.expected_amount_min_money),
+ max: format_money(series.expected_amount_max_money)) %>
+ </p>
+ <% end %>
</div>
<% else %>
<div class="space-y-0.5">
@@ -44,7 +53,7 @@
<p class="text-xs text-secondary">
<%= frequency_label(series) %>
<% if series.account %>&middot; <%= series.account.name %><% end %>
- <% if series.autopay? %>&middot; <%= t("recurring_transactions.pay_action.autopay") %><% end %>
+ <% if (autopay = bills_autopay_label(series)) %>&middot; <%= autopay %><% end %>
</p>
<%# Subscription state is state, not depth, so it stays here. %>
diff --git a/app/views/bills/index.html.erb b/app/views/bills/index.html.erb
index f3d4d9b7d8..8dc17220d5 100644
--- a/app/views/bills/index.html.erb
+++ b/app/views/bills/index.html.erb
@@ -175,14 +175,13 @@
<%= render "bills/occurrence_section",
title: t(".needs_attention"),
occurrences: @overdue,
- date_labels: true,
suggestions: @suggestions_by_occurrence,
meta: (@past_due_total && @past_due_total.amount.positive? ? t(".attention_overdue_total", amount: format_money(@past_due_total)) : nil) %>
</div>
<% end %>
<div class="rounded-xl bg-container-inset space-y-1 p-1">
- <%= render "bills/occurrence_section", title: t(".this_month"), occurrences: @month_rows, date_labels: true, suggestions: @suggestions_by_occurrence, pay_periods: @month_pay_periods %>
+ <%= render "bills/occurrence_section", title: t(".this_month"), occurrences: @month_rows, suggestions: @suggestions_by_occurrence, pay_periods: @month_pay_periods %>
<%= render "bills/occurrence_section", title: t(".later"), occurrences: @later, suggestions: @suggestions_by_occurrence %>
<%= render "bills/occurrence_section", title: t(".dormant"), occurrences: @dormant, suggestions: @suggestions_by_occurrence %>
</div>
diff --git a/app/views/bills/show.html.erb b/app/views/bills/show.html.erb
index 920a88defd..8171b5fd7d 100644
--- a/app/views/bills/show.html.erb
+++ b/app/views/bills/show.html.erb
@@ -16,8 +16,8 @@
<h1 class="text-xl font-medium text-primary"><%= @series.display_name %></h1>
<p class="text-sm text-secondary">
<%= frequency_label(@series) %>
- <% if (progress = @series.installment_progress) %>
- &middot; <%= t("bills.installment_progress", done_plus_one: [ progress.first + 1, progress.last ].min, total: progress.last) %>
+ <% if (progress = bills_installment_progress(@series)) %>
+ &middot; <%= progress %>
<% end %>
&middot; <%= t("recurring_transactions.status.#{@series.status}") %>
</p>
@@ -72,7 +72,7 @@
<%= t("bills.summary.remaining", amount: format_money(@current_occurrence.remaining_amount_money)) %>
<% end %>
</p>
- <p class="text-xs <%= @current_occurrence.overdue? ? "text-destructive" : "text-secondary" %>">
+ <p class="text-xs <%= bills_overdue?(@current_occurrence) ? "text-destructive" : "text-secondary" %>">
<span class="privacy-sensitive">
<%= t("bills.partial_progress",
paid: format_money(@current_occurrence.confirmed_allocated_money),
diff --git a/app/views/recurring_occurrences/show.html.erb b/app/views/recurring_occurrences/show.html.erb
index b1688f9fe5..e5e62cb0a7 100644
--- a/app/views/recurring_occurrences/show.html.erb
+++ b/app/views/recurring_occurrences/show.html.erb
@@ -22,7 +22,7 @@
<h2 id="<%= dialog.title_id %>" class="text-lg font-medium text-primary truncate">
<%= series.display_name %>
</h2>
- <p class="text-sm <%= @occurrence.overdue? ? "text-destructive" : "text-secondary" %>">
+ <p class="text-sm <%= bills_overdue?(@occurrence) ? "text-destructive" : "text-secondary" %>">
<%= occurrence_due_label(@occurrence) %>
</p>
</div>
@@ -66,7 +66,7 @@
<%= render DS::ProgressRing.new(
percent: percent,
size: 56,
- tone: @occurrence.paid? ? :success : (@occurrence.overdue? ? :destructive : :neutral)
+ tone: @occurrence.paid? ? :success : (bills_overdue?(@occurrence) ? :destructive : :neutral)
) %>
</div>
</div>
diff --git a/config/locales/views/bills/ca.yml b/config/locales/views/bills/ca.yml
index 7f70b19a04..9aa102decd 100644
--- a/config/locales/views/bills/ca.yml
+++ b/config/locales/views/bills/ca.yml
@@ -107,8 +107,9 @@ ca:
one: '%{count} dia després del venciment'
other: '%{count} dies després del venciment'
attention:
+ paused: En pausa
needs_review: Cal revisar la coincidència
- partial: Parcial · %{amount} pendents
+ partial: Parcial
amount_changed: L'import ha canviat
overdue:
one: Vençuda fa %{count} dia
@@ -120,7 +121,7 @@ ca:
cancelled_still_scheduled: La vas marcar com a cancel·lada el %{date}, però encara està programada, així que continuaran apareixent factures futures.
paid_over: Pagats %{paid}, més del previst
remaining_label: pendents
- debt_payment: · pagament de deute
+ debt_payment: Pagament de deute
paid_from: des de %{account}
amount_range: entre %{min} i %{max}
possible_duplicate: Possible duplicat
diff --git a/config/locales/views/bills/en.yml b/config/locales/views/bills/en.yml
index faeca3b8d3..b1c590b50e 100644
--- a/config/locales/views/bills/en.yml
+++ b/config/locales/views/bills/en.yml
@@ -109,8 +109,9 @@ en:
one: 1 day after due
other: "%{count} days after due"
attention:
+ paused: Paused
needs_review: Match needs review
- partial: "Partial · %{amount} remaining"
+ partial: Partial
amount_changed: Amount changed
overdue:
one: 1 day overdue
@@ -122,7 +123,7 @@ en:
cancelled_still_scheduled: "You marked this cancelled on %{date}, but it is still scheduled, so future bills will keep appearing."
paid_over: "Paid %{paid}, more than expected"
remaining_label: remaining
- debt_payment: "· debt payment"
+ debt_payment: Debt payment
paid_from: "from %{account}"
amount_range: "ranges %{min} to %{max}"
possible_duplicate: Possible duplicate
diff --git a/config/locales/views/bills/fr.yml b/config/locales/views/bills/fr.yml
index ca9919402f..7cee577f0f 100644
--- a/config/locales/views/bills/fr.yml
+++ b/config/locales/views/bills/fr.yml
@@ -52,7 +52,8 @@ fr:
overdue:
one: 1 jour de retard
other: "%{count} jours de retard"
- partial: Partiel · %{amount} restant
+ partial: Partiel
+ paused: En pause
calendar:
empty_month: Aucune facture à payer ce mois-ci.
month_totals: "%{expected} prévu · %{paid} payé"
@@ -62,7 +63,7 @@ fr:
subscribe_ical: S'abonner (iCal)
today: Aujourd'hui
cancelled_still_scheduled: "Vous l'avez marquée comme annulée le %{date}, mais elle reste programmée : de nouvelles factures continueront donc d'apparaître."
- debt_payment: "· remboursement de dette"
+ debt_payment: Remboursement de dette
detail:
annualized: Par an
around: vers le %{date}
diff --git a/config/locales/views/bills/pl.yml b/config/locales/views/bills/pl.yml
index 700be4ecfe..187629eecb 100644
--- a/config/locales/views/bills/pl.yml
+++ b/config/locales/views/bills/pl.yml
@@ -54,7 +54,8 @@ pl:
many: Zaległe od %{count} dni
one: Zaległe od 1 dnia
other: Zaległe od %{count} dni
- partial: Częściowo · pozostało %{amount}
+ partial: Częściowo
+ paused: Wstrzymane
calendar:
empty_month: Brak rachunków z terminem w tym miesiącu.
month_totals: "%{expected} oczekiwane · %{paid} opłacone"
@@ -65,7 +66,7 @@ pl:
today: Dziś
cancelled_still_scheduled: Oznaczono to jako anulowane %{date}, ale nadal jest
zaplanowane, więc kolejne rachunki będą się pojawiać.
- debt_payment: "· spłata zadłużenia"
+ debt_payment: Spłata zadłużenia
detail:
annualized: Rocznie
around: około %{date}
diff --git a/config/locales/views/bills/ru.yml b/config/locales/views/bills/ru.yml
index 1437e7fdf3..57559c47af 100644
--- a/config/locales/views/bills/ru.yml
+++ b/config/locales/views/bills/ru.yml
@@ -119,8 +119,9 @@ ru:
many: Через %{count} дней после срока
other: Через %{count} дня после срока
attention:
+ paused: Приостановлено
needs_review: Совпадение требует проверки
- partial: Частично · осталось %{amount}
+ partial: Частично
amount_changed: Сумма изменилась
overdue:
one: Просрочено на %{count} день
@@ -134,7 +135,7 @@ ru:
cancelled_still_scheduled: Вы отметили это как отменённое %{date}, но платёж всё ещё запланирован, поэтому будущие платежи продолжат появляться.
paid_over: Оплачено %{paid} — больше ожидаемого
remaining_label: осталось
- debt_payment: · погашение долга
+ debt_payment: Погашение долга
paid_from: со счёта %{account}
amount_range: от %{min} до %{max}
possible_duplicate: Возможный дубликат
diff --git a/config/locales/views/bills/tr.yml b/config/locales/views/bills/tr.yml
index 2f6f947d42..a6dc244e8b 100644
--- a/config/locales/views/bills/tr.yml
+++ b/config/locales/views/bills/tr.yml
@@ -107,8 +107,9 @@ tr:
one: Son ödeme tarihinden %{count} gün sonra
other: Son ödeme tarihinden %{count} gün sonra
attention:
+ paused: Duraklatıldı
needs_review: Eşleşme incelenmeli
- partial: Kısmi · %{amount} kaldı
+ partial: Kısmi
amount_changed: Tutar değişti
overdue:
one: '%{count} gün gecikmiş'
@@ -120,7 +121,7 @@ tr:
cancelled_still_scheduled: Bunu %{date} tarihinde iptal edildi olarak işaretlediniz, ancak hâlâ planlı olduğu için gelecekteki faturalar görünmeye devam edecek.
paid_over: '%{paid} ödendi, beklenenden fazla'
remaining_label: kalan
- debt_payment: ' · borç ödemesi'
+ debt_payment: Borç ödemesi
paid_from: '%{account} hesabından'
amount_range: '%{min} ile %{max} arasında değişir'
possible_duplicate: Olası mükerrer
diff --git a/config/locales/views/bills/uk.yml b/config/locales/views/bills/uk.yml
index 749abb64cb..1ad2afefdb 100644
--- a/config/locales/views/bills/uk.yml
+++ b/config/locales/views/bills/uk.yml
@@ -119,8 +119,9 @@ uk:
many: Через %{count} днів після строку
other: Через %{count} дня після строку
attention:
+ paused: Призупинено
needs_review: Зіставлення потребує перевірки
- partial: Частково · залишилося %{amount}
+ partial: Частково
amount_changed: Сума змінилася
overdue:
one: Прострочено на %{count} день
@@ -134,7 +135,7 @@ uk:
cancelled_still_scheduled: Ви позначили це як скасоване %{date}, але розклад досі активний, тому нові платежі й далі з'являтимуться.
paid_over: Сплачено %{paid}, більше за очікуване
remaining_label: залишилося
- debt_payment: · погашення боргу
+ debt_payment: Погашення боргу
paid_from: з рахунку %{account}
amount_range: від %{min} до %{max}
possible_duplicate: Можливий дублікат
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index 691036a9cc..34d2a73081 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -119,7 +119,11 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_match "Real bill", response.body
assert_match "Card payment", response.body
- assert_match I18n.t("bills.debt_payment"), response.body
+ # On the subline, not after the name, where it truncated to "· d…".
+ assert_select BILL_ROW_LINK, text: /Card payment/ do |links|
+ assert_select links.first, "p.font-medium", text: "Card payment"
+ assert_select links.first, "p.text-xs", text: /#{I18n.t("bills.debt_payment")}/
+ end
assert_no_match "Salary deposit", response.body
assert_no_match "Paused bill", response.body
assert_no_match "Moved to savings", response.body
@@ -169,6 +173,168 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
# Needs attention, where the subline goes on to give the reason.
assert_includes subline_dates, "#{I18n.l(late, format: :short)} ·"
assert_match I18n.t("bills.attention.overdue", count: 5), response.body
+ # Red like the rail, because the reason after it isn't always Overdue: a
+ # match to review or a partial payment outranks it, uncoloured.
+ assert_select "p span.text-destructive[class~='@lg:hidden']", count: 1,
+ text: "#{I18n.l(late, format: :short)} ·"
+ end
+
+ # The rail used to come only with Needs attention and This month, so in the
+ # stacked card This month's avatars sat about 70px right of the others'.
+ test "rows after this month and dormant rows carry the date rail too" do
+ next_month = Date.current.next_month.beginning_of_month + 4
+ later = create_bill(name: "Next month rent", amount: 900, manual: true, anchor_date: next_month,
+ expected_day_of_month: next_month.day, next_expected_date: next_month)
+ late = 6.days.ago.to_date
+ paused = create_bill(name: "Paused gym", amount: 40, expected_day_of_month: late.day,
+ last_occurrence_date: 2.months.ago.to_date, next_expected_date: late)
+ paused.mark_inactive!
+
+ get bills_url
+
+ assert_response :success
+ assert_equal [ later.id ], @controller.view_assigns["later"].map(&:recurring_transaction_id)
+ assert_equal [ paused.id ], @controller.view_assigns["dormant"].map(&:recurring_transaction_id)
+ [ later, paused ].each do |series|
+ occurrence = series.recurring_occurrences.open_status.order(:due_on).first
+ assert_select "a[href=?] div[class~='@lg:block']",
+ bill_path(series, display: "drawer", occurrence: occurrence.id),
+ text: /#{Regexp.escape(I18n.l(occurrence.due_on, format: :short))}/
+ end
+ end
+
+ # Pause stores inactive and keeps the open leftover, which read "Overdue by 6
+ # days" in red with nothing saying the bill was paused.
+ test "a paused bill's leftover reads Paused, with no overdue and no red" do
+ late = 6.days.ago.to_date
+ bill = create_bill(name: "Paused gym", amount: 40, autopay: true, expected_day_of_month: late.day,
+ last_occurrence_date: 2.months.ago.to_date, next_expected_date: late)
+ bill.mark_inactive!
+ occurrence = bill.recurring_occurrences.open_status.sole
+ assert occurrence.overdue?, "premise: the leftover is past its grace"
+
+ get bills_url
+
+ assert_response :success
+ assert_select "a[href=?]", bill_path(bill, display: "drawer", occurrence: occurrence.id) do |links|
+ assert_select links.first, "p.text-xs", text: /#{I18n.t("bills.attention.paused")}/
+ assert_select links.first, "div.text-secondary[class~='@lg:block']"
+ assert_select links.first, ".text-destructive", count: 0
+ assert_no_match(/overdue/i, links.first.text)
+ # A paused bill isn't charging.
+ assert_not_includes links.first.text, I18n.t("recurring_transactions.pay_action.autopay")
+ end
+ end
+
+ # The row calls the leftover Paused, and the drawer it opens, the bill's page
+ # and the payment drawer said "Overdue by 6 days" in red.
+ test "a paused bill's drawer, page and payment drawer say Paused, not overdue" do
+ late = 6.days.ago.to_date
+ bill = create_bill(name: "Paused gym", amount: 40, expected_day_of_month: late.day,
+ last_occurrence_date: 2.months.ago.to_date, next_expected_date: late)
+ bill.mark_inactive!
+ occurrence = bill.recurring_occurrences.open_status.sole
+ assert occurrence.overdue?, "premise: the leftover is past its grace"
+
+ paused = I18n.t("recurring_transactions.status.inactive")
+
+ [ -> { get_bill_drawer(bill) }, -> { get bill_url(bill) }, -> { get recurring_occurrence_url(occurrence) } ].each do |visit|
+ visit.call
+
+ assert_response :success
+ assert_select "p.text-secondary", text: /#{paused} · /
+ assert_select ".text-destructive", text: /#{paused}/, count: 0
+ assert_no_match(/Overdue by/, response.body)
+ end
+
+ # The payment drawer's ring takes the same tone.
+ get recurring_occurrence_url(occurrence)
+ assert_no_match "var(--color-destructive)", response.body
+ end
+
+ # The row drops Autopay once a bill is paused, and the drawer's schedule
+ # line still claimed it.
+ test "a paused bill's drawer schedule leaves out autopay" do
+ bill = create_bill(name: "Paused gym", amount: 40, autopay: true)
+ bill.mark_inactive!
+
+ get_bill_drawer(bill)
+
+ assert_response :success
+ frequency = ApplicationController.helpers.frequency_label(bill)
+ assert_select "p", text: /\A#{Regexp.escape(frequency)}\s*·\s*#{Regexp.escape(bill.account.name)}\z/
+ end
+
+ # Rows after this month said "Snoozed until …". The rail that replaced that
+ # line printed the old day, and the list kept the old order.
+ test "a snoozed row sits at the date it was snoozed to" do
+ next_month = Date.current.next_month.beginning_of_month
+ snoozed = create_bill(name: "Snoozed gym", amount: 40, manual: true, anchor_date: next_month + 3,
+ expected_day_of_month: (next_month + 3).day, next_expected_date: next_month + 3)
+ create_bill(name: "Next month rent", amount: 900, manual: true, anchor_date: next_month + 7,
+ expected_day_of_month: (next_month + 7).day, next_expected_date: next_month + 7)
+ occurrence = snoozed.recurring_occurrences.open_status.order(:due_on).first
+ occurrence.snooze!(next_month + 12)
+
+ get bills_url
+
+ assert_response :success
+ assert_equal [ "Next month rent", "Snoozed gym" ], @controller.view_assigns["later"].map { |o| o.recurring_transaction.name }
+ assert_select "a[href=?] div[class~='@lg:block']",
+ bill_path(snoozed, display: "drawer", occurrence: occurrence.id),
+ text: /#{Regexp.escape(I18n.l(next_month + 12, format: :short))}/
+ end
+
+ # The app snoozes a week. An overdue bill snoozed mid-month moves down This
+ # month to its new date, after a bill due sooner.
+ test "a bill snoozed a week lists at its new date" do
+ travel_to Date.current.beginning_of_month + 9.days
+ create_bill(name: "Soon Co", amount: 20, manual: true, anchor_date: Date.current + 3,
+ expected_day_of_month: (Date.current + 3).day, next_expected_date: Date.current + 3)
+ late = 6.days.ago.to_date
+ bill = create_bill(name: "Late Co", amount: 30, expected_day_of_month: late.day,
+ last_occurrence_date: 2.months.ago.to_date, next_expected_date: late)
+ bill.recurring_occurrences.open_status.order(:due_on).first.snooze!(Date.current + 7)
+
+ get bills_url
+
+ assert_response :success
+ assert_equal [ "Soon Co", "Late Co" ], @controller.view_assigns["month_rows"].map { |o| o.recurring_transaction.name }
+ end
+
+ # Snoozed past the month's end, the bill was left at the bottom of This
+ # month with next month's date on its rail.
+ test "a bill snoozed past the month's end moves after this month" do
+ travel_to Date.current.end_of_month - 2.days
+ late = 6.days.ago.to_date
+ bill = create_bill(name: "Late Co", amount: 30, expected_day_of_month: late.day,
+ last_occurrence_date: 2.months.ago.to_date, next_expected_date: late)
+ occurrence = bill.recurring_occurrences.open_status.order(:due_on).first
+ occurrence.snooze!(Date.current + 7)
+
+ get bills_url
+
+ assert_response :success
+ assert_empty @controller.view_assigns["month_rows"]
+ assert_equal [ occurrence.id ], @controller.view_assigns["later"].map(&:id)
+ end
+
+ # On a phone the range squeezed the bill's name to "PG&E Ele…", so the row
+ # shows it only from @lg and the drawer carries it.
+ test "an estimated bill's range leaves the row on a phone and stays in the drawer" do
+ bill = create_bill(name: "Power Co", amount: 96.40, amount_strategy: "average", expected_amount_avg: 96.40,
+ expected_amount_min: 71.12, expected_amount_max: 131.80)
+ range = I18n.t("bills.amount_range", min: "$71.12", max: "$131.80")
+
+ get bills_url
+ assert_response :success
+ assert_select BILL_ROW_LINK, text: /Power Co/ do |links|
+ assert_select links.first, "p[class~='hidden'][class~='@lg:block']", text: range
+ end
+
+ get_bill_drawer(bill)
+ assert_response :success
+ assert_match range, response.body
end
# "%b %-d" is English order in every locale; fr, pl and ru put the day first.
@@ -311,28 +477,6 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_includes next_up.map { |o| o.recurring_transaction.display_name }, "Soon Co"
end
- # Three tiers of one subscription are three real bills that render as three
- # identical rows. Only then does a row earn a second fact.
- test "bills that would render identically gain something that tells them apart" do
- day = 12.days.from_now.to_date
- 2.times do |i|
- create_bill(name: "TWITCH", amount: 11.99, manual: true, dedup_scope: "tier#{i}",
- anchor_date: day, expected_day_of_month: day.day,
- last_occurrence_date: Date.current, next_expected_date: day)
- end
- create_bill(name: "Distinct Co", amount: 30, manual: true,
- anchor_date: day, expected_day_of_month: day.day,
- last_occurrence_date: Date.current, next_expected_date: day)
-
- get bills_url
- assert_response :success
-
- # The pair carries its schedule; the bill nobody could confuse does not
- # pay for their ambiguity.
- twitch_rows = response.body.scan(/TWITCH/).size
- assert_operator twitch_rows, :>=, 2
- end
-
# Overdue rows used to sit inside the chronological month list, marked only by
# a word where their date would be, which made the most urgent rows the
# easiest to scroll past.
@@ -499,13 +643,15 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
get bills_url
assert_response :success
- # What is left leads, and the row says it once. The subline carries the
- # state and the figure; printing "$750.00 of $2,000.00 paid" again on the
- # right was the same arithmetic twice, and it was squeezing the bill's own
- # name out of the row.
- assert_match I18n.t("bills.attention.partial", amount: "$1,250.00"), response.body
- assert_match "$1,250", response.body
- assert_no_match I18n.t("bills.partial_progress", paid: "$750.00", expected: "$2,000.00"), response.body
+ # What is left leads, and the row says it once: Partial on the left, the
+ # remainder on the right. The subline used to repeat "$1,250.00
+ # remaining", which squeezed the bill's own name out of the row.
+ assert_select BILL_ROW_LINK, text: /Rent/ do |links|
+ assert_select links.first, "p.text-xs", text: /#{I18n.t("bills.attention.partial")}/
+ assert_select links.first, "p.privacy-sensitive", text: "$1,250.00"
+ assert_select links.first, "p", text: I18n.t("bills.remaining_label")
+ assert_equal 1, links.first.text.scan("$1,250.00").size, "the remainder is printed once"
+ end
end
# The row's detail once described the SERIES definition while the bill's
diff --git a/test/helpers/bills_helper_test.rb b/test/helpers/bills_helper_test.rb
index d0f69e0941..d41023d742 100644
--- a/test/helpers/bills_helper_test.rb
+++ b/test/helpers/bills_helper_test.rb
@@ -5,6 +5,8 @@ class BillsHelperTest < ActionView::TestCase
# bills_match_reasons formats one money value, and format_money lives in
# ApplicationHelper rather than this module.
include ApplicationHelper
+ # A bill row's subline names its schedule through frequency_label.
+ include RecurringTransactionsHelper
test "an upcoming date gains the year only when it falls in another one" do
travel_to Date.new(2026, 9, 25) do
@@ -222,20 +224,163 @@ class BillsHelperTest < ActionView::TestCase
assert_match(/overdue/i, occurrence_due_label(occurrence))
end
- # --- Prepared-data helpers extracted from the templates, so the section,
- # pulse, detail and paycheck views render precomputed values. ---
+ # --- What a bill row says ---
+
+ # First true wins. A paused bill's leftover used to read "Overdue by 6 days"
+ # with nothing saying the bill was paused, and lateness now outranks a price
+ # change.
+ test "a row gives the first reason that applies, paused first" do
+ occurrence = build_occurrence(due_on: Date.current - 30, status: "scheduled")
+ series = occurrence.recurring_transaction
+ price_change!(series, from: 10, to: 12)
+ occurrence.cached_confirmed_allocated = 5
+
+ series.status = "inactive"
+ assert_equal I18n.t("bills.attention.paused"), bills_attention_reason(occurrence, suggestion: :pending)
+
+ series.status = "active"
+ assert_equal I18n.t("bills.attention.needs_review"), bills_attention_reason(occurrence, suggestion: :pending)
+ assert_equal I18n.t("bills.attention.partial"), bills_attention_reason(occurrence)
+
+ occurrence.cached_confirmed_allocated = 0
+ assert_equal %(<span class="text-destructive">#{I18n.t("bills.attention.overdue", count: 30)}</span>),
+ bills_attention_reason(occurrence)
+ end
+
+ # The notices file anything under a tenth as a smaller change, so the row
+ # holds the same line: +4% on Spotify used to push Autopay off the row.
+ test "amount changed needs a shift of a tenth or more" do
+ occurrence = build_occurrence(due_on: Date.current + 5, status: "scheduled")
+ series = occurrence.recurring_transaction
+
+ price_change!(series, from: 100, to: 109.99)
+ assert_nil bills_attention_reason(occurrence), "just under a tenth"
+
+ series.recurring_price_changes.destroy_all
+ price_change!(series, from: 100, to: 110)
+ assert_equal I18n.t("bills.attention.amount_changed"), bills_attention_reason(occurrence), "a tenth"
+ end
+
+ # One order in every section, and the line truncates from the end, so the
+ # facts you can do without come last.
+ test "a row's subline reads autopay, reason, progress, debt payment, schedule, account" do
+ stubs(:bills_span_multiple_accounts?).returns(true)
+ occurrence = build_occurrence(due_on: Date.current + 5, status: "scheduled")
+ series = occurrence.recurring_transaction
+ series.assign_attributes(autopay: true, bill_type: "installment", end_mode: "after_count",
+ end_after_count: 12, destination_account_id: accounts(:credit_card).id)
+ price_change!(series, from: 10, to: 12)
+ facts = [
+ I18n.t("bills.attention.amount_changed"), I18n.t("bills.installment_progress", done_plus_one: 1, total: 12),
+ I18n.t("bills.debt_payment"), frequency_label(series), I18n.t("bills.paid_from", account: series.account.name)
+ ]
+
+ assert_equal [ I18n.t("recurring_transactions.pay_action.autopay"), *facts ].join(" · "),
+ bills_row_subline(occurrence)
+
+ # A paused bill isn't charging, so it drops Autopay.
+ series.status = "inactive"
+ assert_equal [ I18n.t("bills.attention.paused"), *facts.drop(1) ].join(" · "), bills_row_subline(occurrence)
+ end
+
+ # A plan settled in full still lists its last row this month, which read
+ # "Payment 13 of 12".
+ test "installment progress stops at the plan's last payment" do
+ assert_equal I18n.t("bills.installment_progress", done_plus_one: 5, total: 12),
+ bills_installment_progress(OpenStruct.new(installment_progress: [ 4, 12 ]))
+ assert_equal I18n.t("bills.installment_progress", done_plus_one: 12, total: 12),
+ bills_installment_progress(OpenStruct.new(installment_progress: [ 12, 12 ]))
+ assert_nil bills_installment_progress(OpenStruct.new(installment_progress: nil))
+ end
+
+ # The red sits on the overdue reason, not the whole line. On a late bill a
+ # match to review or a partial payment outranks it, and in red they read as
+ # the problem themselves. Never on a paused bill's leftover: nobody is
+ # paying it, so it isn't late.
+ test "only the overdue reason is red" do
+ stubs(:bills_span_multiple_accounts?).returns(false)
+ occurrence = build_occurrence(due_on: Date.current - 30, status: "scheduled")
+ reason = I18n.t("bills.attention.overdue", count: 30)
+
+ assert_includes bills_row_subline(occurrence), %(<span class="text-destructive">#{reason}</span>)
+ assert bills_overdue?(occurrence)
+
+ assert_includes bills_row_subline(occurrence, suggestion: :pending), I18n.t("bills.attention.needs_review")
+ assert_not_includes bills_row_subline(occurrence, suggestion: :pending), "text-destructive"
+
+ occurrence.cached_confirmed_allocated = 5
+ assert_includes bills_row_subline(occurrence), I18n.t("bills.attention.partial")
+ assert_not_includes bills_row_subline(occurrence), "text-destructive"
+ occurrence.cached_confirmed_allocated = 0
+
+ occurrence.recurring_transaction.status = "inactive"
+ assert_not_includes bills_row_subline(occurrence), "text-destructive"
+ assert_not bills_overdue?(occurrence)
+ end
+
+ # The drawer, the bill's page and the payment drawer print this label, and
+ # said "Overdue by 30 days" in red beside a row that reads Paused. A
+ # dismissed bill's page reads Dismissed, so its label does too.
+ test "a leftover of a bill that isn't active leads with the bill's status, not overdue" do
+ occurrence = build_occurrence(due_on: Date.current - 30, status: "scheduled")
+
+ %w[inactive ended].each do |status|
+ occurrence.recurring_transaction.status = status
+ label = occurrence_due_label(occurrence)
+
+ assert label.start_with?(I18n.t("recurring_transactions.status.#{status}")), label
+ assert_includes label, bills_upcoming_date(Date.current - 30)
+ assert_no_match(/overdue/i, label)
+ end
+ end
+
+ # The rail is 56px wide, so "Jan 03, 2027" wrapped mid-date there.
+ test "the rail puts another year's date on two lines" do
+ travel_to Date.new(2026, 10, 16) do
+ next_year = build_occurrence(due_on: Date.new(2027, 1, 3), status: "scheduled")
+ this_year = build_occurrence(due_on: Date.new(2026, 11, 3), status: "scheduled")
- test "ambiguous row keys mark only genuine collisions" do
- twin_a = stub_occurrence("Twitch", 5.99, id: "a1")
- twin_b = stub_occurrence("Twitch", 5.99, id: "a2")
- other_tier = stub_occurrence("Twitch", 11.99, id: "b")
+ rail = Nokogiri::HTML.fragment(bills_rail_date(next_year))
+ assert_equal I18n.l(Date.new(2027, 1, 3), format: :short), rail.children.first.text.strip
+ assert_equal "2027", rail.at_css("span.block.text-subdued")&.text
+ assert_equal I18n.l(Date.new(2026, 11, 3), format: :short), bills_rail_date(this_year)
+ end
+ end
- keys = bills_ambiguous_row_keys([ twin_a, twin_b, other_tier ])
+ # derived_state, the overdue count and Next up all judge a snoozed bill by
+ # the date it was snoozed to. The rail read due_on, so it kept the old day.
+ test "a snoozed row shows the date it was snoozed to" do
+ travel_to Date.new(2026, 12, 28) do
+ occurrence = build_occurrence(due_on: Date.current, status: "scheduled")
+ occurrence.snoozed_until = Date.new(2027, 1, 4)
- assert_includes keys, [ "Twitch", 5.99 ]
- assert_not_includes keys, [ "Twitch", 11.99 ]
+ assert_equal I18n.l(Date.new(2027, 1, 4), format: :short_with_year), bills_row_date(occurrence)
+ rail = Nokogiri::HTML.fragment(bills_rail_date(occurrence))
+ assert_equal I18n.l(Date.new(2027, 1, 4), format: :short), rail.children.first.text.strip
+ assert_equal "2027", rail.at_css("span.block.text-subdued")&.text
+ end
end
+ # Missing keys fall back to English silently, and the helper no longer passes
+ # an amount, so a stale "%{amount}" in one locale would raise on the page.
+ test "every locale with row reasons has Paused, a bare Partial and a bare Debt payment" do
+ locales = Rails.root.glob("config/locales/views/bills/*.yml").map { |file| file.basename(".yml").to_s }
+ .select { |locale| I18n.t("bills.attention", locale: locale, fallback: false, default: nil) }
+ assert_includes locales, "en"
+
+ locales.each do |locale|
+ lookup = ->(key) { I18n.t(key, locale: locale, fallback: false, default: nil).to_s }
+ %w[bills.attention.paused bills.attention.partial bills.debt_payment].each do |key|
+ assert lookup.(key).present?, "#{locale} is missing #{key}"
+ end
+ assert_no_match(/%\{/, lookup.("bills.attention.partial"), "#{locale}'s Partial still interpolates")
+ assert_no_match(/\A[[:space:]·]/, lookup.("bills.debt_payment"), "#{locale}'s Debt payment still leads with a separator")
+ end
+ end
+
+ # --- Prepared-data helpers extracted from the templates, so the section,
+ # pulse, detail and paycheck views render precomputed values. ---
+
test "pay period markers land on the first row of each period with its summed total" do
period = OpenStruct.new(starts_on: Date.new(2026, 9, 1), ends_on: Date.new(2026, 9, 14))
first_inside = stub_occurrence("Rent", 2150, id: "one", due_on: Date.new(2026, 9, 2))
@@ -249,6 +394,22 @@ class BillsHelperTest < ActionView::TestCase
assert_equal period, markers["one"][:period]
end
+ # The list is in rail order, so a bill snoozed into the next pay period sits
+ # under that period's marker and counts toward its total.
+ test "a snoozed row's pay period is the one it was snoozed into" do
+ this_week = OpenStruct.new(starts_on: Date.new(2026, 9, 15), ends_on: Date.new(2026, 9, 21))
+ next_week = OpenStruct.new(starts_on: Date.new(2026, 9, 22), ends_on: Date.new(2026, 9, 28))
+ rent = stub_occurrence("Rent", 900, id: "rent", due_on: Date.new(2026, 9, 16))
+ snoozed = stub_occurrence("Gym", 40, id: "gym", due_on: Date.new(2026, 9, 17), effective_due_on: Date.new(2026, 9, 24))
+ power = stub_occurrence("Power", 80, id: "power", due_on: Date.new(2026, 9, 25))
+
+ markers = bills_pay_period_markers([ rent, snoozed, power ], [ this_week, next_week ])
+
+ assert_equal %w[rent gym], markers.keys
+ assert_equal 900, markers["rent"][:due_total]
+ assert_equal 120, markers["gym"][:due_total]
+ end
+
test "no pay periods means no markers" do
occurrence = stub_occurrence("Rent", 1, id: "x", due_on: Date.current)
@@ -417,10 +578,11 @@ class BillsHelperTest < ActionView::TestCase
private
- def stub_occurrence(name, amount, id:, due_on: Date.current)
+ def stub_occurrence(name, amount, id:, due_on: Date.current, effective_due_on: due_on)
OpenStruct.new(
id: id,
due_on: due_on,
+ effective_due_on: effective_due_on,
resolved_expected_amount: amount,
recurring_transaction: OpenStruct.new(display_name: name)
)
@@ -443,6 +605,11 @@ class BillsHelperTest < ActionView::TestCase
)
end
+ def price_change!(series, from:, to:)
+ series.recurring_price_changes.create!(effective_on: Date.current - 5, previous_amount: from,
+ new_amount: to, currency: "USD", source: "detected")
+ end
+
def build_partial(due_on:, series: {})
occurrence = build_occurrence(due_on: due_on, status: "scheduled", series: series)
occurrence.allocations.create!(allocated_amount: 5, currency: "USD", source: "user_created")
diff --git a/test/models/recurring_price_change_test.rb b/test/models/recurring_price_change_test.rb
new file mode 100644
index 0000000000..43320315ba
--- /dev/null
+++ b/test/models/recurring_price_change_test.rb
@@ -0,0 +1,18 @@
+require "test_helper"
+
+class RecurringPriceChangeTest < ActiveSupport::TestCase
+ # One threshold for the notices and the bill row: a tenth either way.
+ test "a change is material from a tenth either way" do
+ { 109.99 => false, 110 => true, 90 => true, 90.01 => false }.each do |new_amount, material|
+ change = RecurringPriceChange.new(previous_amount: 100, new_amount: new_amount)
+ assert_equal material, change.material?, "100 to #{new_amount}"
+ end
+ end
+
+ test "a change from nothing has no shift to measure" do
+ change = RecurringPriceChange.new(previous_amount: 0, new_amount: 12)
+
+ assert_equal 0, change.shift
+ assert_not change.material?
+ end
+end
diff --git a/test/system/declare_and_pay_bill_test.rb b/test/system/declare_and_pay_bill_test.rb
index 0becbd77a3..3a1ca8a2ea 100644
--- a/test/system/declare_and_pay_bill_test.rb
+++ b/test/system/declare_and_pay_bill_test.rb
@@ -71,7 +71,11 @@ class DeclareAndPayBillTest < ApplicationSystemTestCase
# Linking lands back on the worklist, and the row must say the bill is
# partly paid rather than settled: $537.50 against $2,150 is not rent.
- assert_text I18n.t("bills.attention.partial", amount: "$1,612.50")
+ within(find("[class~='@container'] a[data-turbo-frame=drawer]", text: I18n.t("bills.attention.partial"))) do
+ assert_text "Watson Property"
+ assert_text "$1,612.50"
+ assert_text I18n.t("bills.remaining_label")
+ end
# Journey C picks up exactly where that leaves off. The bill is still ten
# days out, so its row stays quiet; the drawer's verb has become Add