Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Lead the bills overview with the bills, late ones first (#4092)

Guillem Arias Fauste9f877afecf00
diff --git a/app/views/bills/_occurrence_section.html.erb b/app/views/bills/_occurrence_section.html.erb
index 8ba8412540..60221461dd 100644
--- a/app/views/bills/_occurrence_section.html.erb
+++ b/app/views/bills/_occurrence_section.html.erb
@@ -1,10 +1,10 @@
-<%# locals: (title:, occurrences:, suggestions: {}, meta: nil, pay_periods: [], inset: false) %>
+<%# locals: (title:, occurrences:, suggestions: {}, meta: nil, pay_periods: []) %>
<% return if occurrences.empty? %>
<% markers = bills_pay_period_markers(occurrences, pay_periods) %>
<%# No shell by default: bills/index stacks the month sections in one. %>
-<%= render DS::Section.new(title: title, count: occurrences.size, inset: inset) do |section| %>
+<%= render DS::Section.new(title: title, count: occurrences.size, inset: false) do |section| %>
<% section.with_aside { tag.p(meta, class: "text-xs text-secondary privacy-sensitive shrink-0") } if meta %>
<% occurrences.each do |occurrence| %>
<%# The marker belongs to the first row of its period, so it lands
diff --git a/app/views/bills/index.html.erb b/app/views/bills/index.html.erb
index 357313fbb0..e792697c57 100644
--- a/app/views/bills/index.html.erb
+++ b/app/views/bills/index.html.erb
@@ -32,41 +32,71 @@
<%= render "bills/ai_prompts", prompts: %w[due_before_paycheck subscriptions_up monthly_subscriptions] %>
<% end %>
- <%# Changes worth knowing about, ranked by whether you can still do anything.
- Everything stays on the page: the quieter half collapses rather than
- being capped, so nothing becomes a dead end and nothing pushes the
- worklist off screen. %>
- <% if @notices.any? %>
- <% urgent, routine = @notices.partition(&:urgent?) %>
- <%= render DS::Section.new(title: t(".notices_heading"), count: @notices.size) do %>
- <% urgent.each do |notice| %>
- <%= render "bills/notice", notice: notice, urgent: true %>
- <% end %>
-
- <% if routine.any? && urgent.any? %>
- <%# A row of the card like the notices around it. Its old grey
- summary read as a box inside the card. %>
- <%= render DS::Disclosure.new(variant: :inline, body_class: nil) do |disclosure| %>
- <% disclosure.with_summary_content do %>
- <div class="flex items-center gap-2 px-4 py-2.5 text-sm text-secondary">
- <%= disclosure_chevron %>
- <span><%= t(".notices_routine", count: routine.size) %></span>
+ <% if bill_rows_empty %>
+ <% if @suggested_series.none? %>
+ <div class="bg-container rounded-xl shadow-border-xs p-4">
+ <%= render DS::EmptyState.new(
+ icon: "receipt",
+ title: t(".empty.title"),
+ description: @has_transaction_history ? t(".empty.description") : t(".empty.no_history_description")
+ ) do |empty| %>
+ <% empty.with_action do %>
+ <div class="flex flex-wrap items-center justify-center gap-2">
+ <% if @has_transaction_history %>
+ <%= render DS::Link.new(
+ text: t(".empty.action"),
+ icon: "search",
+ variant: "primary",
+ href: detect_bills_path,
+ method: :post
+ ) %>
+ <%= render DS::Link.new(
+ text: t(".add_bill"),
+ icon: "plus",
+ variant: "outline",
+ href: new_recurring_transaction_path,
+ frame: :modal
+ ) %>
+ <% else %>
+ <%# Detection over zero transactions finds nothing; offering it
+ would be a button that silently does nothing. %>
+ <%= render DS::Link.new(
+ text: t(".add_bill"),
+ icon: "plus",
+ variant: "primary",
+ href: new_recurring_transaction_path,
+ frame: :modal
+ ) %>
+ <% end %>
</div>
<% end %>
- <div class="divide-y divide-subdued border-t border-subdued">
- <% routine.each do |notice| %>
- <%= render "bills/notice", notice: notice, urgent: false %>
- <% end %>
- </div>
<% end %>
- <% else %>
- <% routine.each do |notice| %>
- <%= render "bills/notice", notice: notice, urgent: false %>
- <% end %>
- <% end %>
+ </div>
<% end %>
+ <% else %>
+ <%# One list, what is late first, the way Budgets leads its categories
+ with Over budget. Anything late is still pulled out of the
+ chronological run: inside it, an overdue bill was distinguishable only
+ by a word in the date column, so the most urgent rows were the easiest
+ ones to scroll past. It used to sit below the review queues and the
+ notices, a screen down from the pulse that totals it. %>
+ <%# The section says how much is at stake, not just how many rows: a
+ count alone is alarming without being informative. %>
+ <div class="rounded-xl bg-surface-inset space-y-1 p-1">
+ <%= render "bills/occurrence_section",
+ title: t(".needs_attention"),
+ occurrences: @overdue,
+ suggestions: @suggestions_by_occurrence,
+ meta: (@past_due_total && @past_due_total.amount.positive? ? t(".attention_overdue_total", amount: format_money(@past_due_total)) : nil) %>
+ <%= 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>
<% end %>
+ <%# What is waiting on a yes or no sits under the bills it is about. A row
+ with a match to review already says so and offers Review match, so
+ nothing here is only reachable from up top. %>
<% if @suggested_allocations.any? %>
<%= render DS::Section.new(title: t(".needs_review"), count: @suggested_allocations.size) do %>
<% @suggested_allocations.each do |suggestion| %>
@@ -117,65 +147,40 @@
<%= render "recurring_transactions/suggested_series", suggested: @suggested_series %>
<% end %>
- <% if bill_rows_empty %>
- <% if @suggested_series.none? %>
- <div class="bg-container rounded-xl shadow-border-xs p-4">
- <%= render DS::EmptyState.new(
- icon: "receipt",
- title: t(".empty.title"),
- description: @has_transaction_history ? t(".empty.description") : t(".empty.no_history_description")
- ) do |empty| %>
- <% empty.with_action do %>
- <div class="flex flex-wrap items-center justify-center gap-2">
- <% if @has_transaction_history %>
- <%= render DS::Link.new(
- text: t(".empty.action"),
- icon: "search",
- variant: "primary",
- href: detect_bills_path,
- method: :post
- ) %>
- <%= render DS::Link.new(
- text: t(".add_bill"),
- icon: "plus",
- variant: "outline",
- href: new_recurring_transaction_path,
- frame: :modal
- ) %>
- <% else %>
- <%# Detection over zero transactions finds nothing; offering it
- would be a button that silently does nothing. %>
- <%= render DS::Link.new(
- text: t(".add_bill"),
- icon: "plus",
- variant: "primary",
- href: new_recurring_transaction_path,
- frame: :modal
- ) %>
- <% end %>
+ <%# Changes worth knowing about, ranked by whether you can still do anything.
+ Last on the page: they inform rather than ask, so they follow the
+ worklist instead of pushing it off screen. Everything stays on the page:
+ the quieter half collapses rather than being capped, so nothing becomes
+ a dead end. %>
+ <% if @notices.any? %>
+ <% urgent, routine = @notices.partition(&:urgent?) %>
+ <%= render DS::Section.new(title: t(".notices_heading"), count: @notices.size) do %>
+ <% urgent.each do |notice| %>
+ <%= render "bills/notice", notice: notice, urgent: true %>
+ <% end %>
+
+ <% if routine.any? && urgent.any? %>
+ <%# A row of the card like the notices around it. Its old grey
+ summary read as a box inside the card. %>
+ <%= render DS::Disclosure.new(variant: :inline, body_class: nil) do |disclosure| %>
+ <% disclosure.with_summary_content do %>
+ <div class="flex items-center gap-2 px-4 py-2.5 text-sm text-secondary">
+ <%= disclosure_chevron %>
+ <span><%= t(".notices_routine", count: routine.size) %></span>
</div>
<% end %>
+ <div class="divide-y divide-subdued border-t border-subdued">
+ <% routine.each do |notice| %>
+ <%= render "bills/notice", notice: notice, urgent: false %>
+ <% end %>
+ </div>
<% end %>
- </div>
+ <% else %>
+ <% routine.each do |notice| %>
+ <%= render "bills/notice", notice: notice, urgent: false %>
+ <% end %>
+ <% end %>
<% end %>
- <% else %>
- <%# Anything late is pulled out of the chronological run. Inside it, an
- overdue bill was distinguishable only by a word in the date column, so
- the most urgent rows were the easiest ones to scroll past. %>
- <%# The section says how much is at stake, not just how many rows: a
- count alone is alarming without being informative. %>
- <%= render "bills/occurrence_section",
- title: t(".needs_attention"),
- occurrences: @overdue,
- inset: 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 class="rounded-xl bg-surface-inset space-y-1 p-1">
- <%= 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>
<% end %>
</div>
</div>
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index c514738c5f..c11af400e0 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -1863,6 +1863,37 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_equal 1, chevrons.map(&:to_html).uniq.size, "the folds' chevrons differ: #{chevrons.map { |svg| svg["class"] }.inspect}"
end
+ # The pulse totals what is owed, so the bills come next, late ones first, the
+ # way Budgets leads its categories with Over budget. The queues waiting on a
+ # yes or no follow, and the notices, which only inform, close the page.
+ test "the overview leads with the bills, late ones first, then the queues and the notices" do
+ trial = create_bill(name: "Streamflix", amount: 20)
+ trial.update!(bill_type: "subscription", trial_ends_on: Date.current + 1)
+ create_bill(name: "Rent", amount: 1200)
+ overdue_day = 10.days.ago.to_date
+ create_bill(name: "Late bill", amount: 75, expected_day_of_month: overdue_day.day,
+ last_occurrence_date: 2.months.ago.to_date, next_expected_date: overdue_day)
+ water = declare_bill(name: "CITY WATER", amount: 80, due: Date.current - 3)
+ charge = create_transaction_entry(name: "CITY WATER", amount: 85.50, date: Date.current - 3)
+ RecurringTransaction::Allocator.new(water.recurring_occurrences.order(:due_on).first).allocate_matched!(
+ entry: charge, state: "suggested", confidence: 0.7, signals: { name: 0.35 }
+ )
+ create_suggested(name: "Hulu", account: accounts(:depository))
+
+ get bills_url
+ assert_response :success
+
+ order = [ I18n.t("bills.index.needs_attention"), I18n.t("bills.index.this_month"),
+ I18n.t("bills.index.needs_review"), I18n.t("recurring_transactions.suggested.title"),
+ I18n.t("bills.index.notices_heading") ]
+ headings = css_select("main h2").map { |heading| heading.text.squish }
+ assert_equal order, headings & order
+
+ # Late bills open the same list as the month, not a shell of their own.
+ list = css_select("main .bg-surface-inset").find { |shell| css_select(shell, "h2").any? { |h| h.text.squish == I18n.t("bills.index.this_month") } }
+ assert_includes css_select(list, "h2").map { |heading| heading.text.squish }, I18n.t("bills.index.needs_attention")
+ end
+
test "a price notice says how big the change was" do
bill = create_bill(name: "Gym", amount: 90)
bill.recurring_price_changes.create!(effective_on: 5.days.ago.to_date,