The personal finance app for everyone (by everyone)
Ruby
Keep dismissed bills out of current bill lists (#4581)
Shibu M5accbf24b79b
diff --git a/app/controllers/bills_controller.rb b/app/controllers/bills_controller.rbindex 3e78017776..2c11af7f8a 100644--- a/app/controllers/bills_controller.rb+++ b/app/controllers/bills_controller.rb@@ -306,6 +306,12 @@ class BillsController < ApplicationControllerif status.presence_in(LIFECYCLE_FILTERS)scope = scope.where(status: LIFECYCLE_STATUSES.fetch(status))+ else+ # A removed detected bill stays as an ended tombstone so detection+ # does not recreate it. It is not a current bill, so keep it out of+ # the default list and out of the payment-state filters. The Dismissed+ # filter above is the way to find it.+ scope = scope.where.not(status: :ended)endif (bill_type = params.dig(:q, :bill_type)).presence_in(RecurringTransaction.bill_types.keys)@@ -322,6 +328,18 @@ class BillsController < ApplicationController@all_series = filter_by_payment_state(@all_series, status) if status.presence_in(PAYMENT_FILTERS)+ # A family whose only bills are dismissed tombstones gets an empty list.+ # Say why, so the empty state can point at the Dismissed filter instead+ # of telling the user to clear a filter they never set.+ @dismissed_series_hidden = @all_series.empty? &&+ status.blank? &&+ params.dig(:q, :search).blank? &&+ params.dig(:q, :bill_type).blank? &&+ Current.family.recurring_transactions+ .accessible_by(Current.user)+ .ended+ .exists?+load_subscription_rollup if bill_type == "subscription"end@@ -361,7 +379,9 @@ class BillsController < ApplicationController@recent_price_changes = RecurringPriceChange.joins(:recurring_transaction).merge(RecurringTransaction.accessible_by(Current.user))- .where(recurring_transactions: { family_id: Current.family.id })+ .where(recurring_transactions: { family_id: Current.family.id,+ bill_type: "subscription" })+ .where.not(recurring_transactions: { status: "ended" }).where("effective_on >= ?", 1.year.ago.to_date).includes(:recurring_transaction).order(effective_on: :desc)diff --git a/app/views/bills/all.html.erb b/app/views/bills/all.html.erbindex 9e4b3cf3e1..5d093af09c 100644--- a/app/views/bills/all.html.erb+++ b/app/views/bills/all.html.erb@@ -49,7 +49,7 @@data: { "auto-submit-form-target": "auto" }) %><%= form.select :status,options_for_select(- [ [ t(".any_status"), "" ] ] + BillsController::STATUS_FILTERS.map { |status| [ t(".status_filters.#{status}"), status ] },+ [ [ t(".current_bills"), "" ] ] + BillsController::STATUS_FILTERS.map { |status| [ t(".status_filters.#{status}"), status ] },params.dig(:q, :status)),{ container_class: "w-auto py-2.5" },@@ -71,11 +71,28 @@<% end %><% if @all_series.empty? %>- <%= render DS::EmptyState.new(- icon: "receipt",- title: t(".no_matches_title"),- description: t(".no_matches_description")- ) %>+ <% if @dismissed_series_hidden %>+ <%= render DS::EmptyState.new(+ icon: "receipt",+ title: t(".no_matches_title"),+ description: t(".dismissed_hidden_description")+ ) do |empty| %>+ <% empty.with_action do %>+ <%= render DS::Link.new(+ text: t(".status_filters.ended"),+ icon: "receipt",+ variant: "outline",+ href: bills_path(view: "all", q: { status: "ended" })+ ) %>+ <% end %>+ <% end %>+ <% else %>+ <%= render DS::EmptyState.new(+ icon: "receipt",+ title: t(".no_matches_title"),+ description: t(".no_matches_description")+ ) %>+ <% end %><% else %><%# A table on a phone is a table you scroll sideways to read. The samerows, laid out the way the Calendar already does it: a purpose-builtdiff --git a/config/locales/views/bills/ca.yml b/config/locales/views/bills/ca.ymlindex 2b4bcd72f3..76eaffb7b8 100644--- a/config/locales/views/bills/ca.yml+++ b/config/locales/views/bills/ca.yml@@ -216,7 +216,8 @@ ca:empty_month: Aquest mes no venç cap factura.all:search_placeholder: Cerca factures- any_status: Qualsevol estat+ current_bills: Factures actuals+ dismissed_hidden_description: Les factures descartades estan ocultes.status_filters:overdue: Vençudesdue: Vencen aviatdiff --git a/config/locales/views/bills/de.yml b/config/locales/views/bills/de.ymlindex ab51582adc..6872ffe2cd 100644--- a/config/locales/views/bills/de.yml+++ b/config/locales/views/bills/de.yml@@ -18,9 +18,22 @@ de:calendar: Kalenderpaycheck: Einkommensplanall: Alle Rechnungen+ all:+ current_bills: Aktuelle Rechnungen+ dismissed_hidden_description: Verworfene Rechnungen sind ausgeblendet.+ no_matches_title: Keine Treffer+ no_matches_description: Entferne einen Filter oder die Suche.+ status_filters:+ overdue: Überfällig+ due: Bald fällig+ partial: Teilweise bezahlt+ paid: Bezahlt+ paused: Pausiert+ ended: Verworfenindex:title: Rechnungenadd_bill: Neue Rechnungadd_income: Neues Einkommenreview_with_ai: Mit KI prüfennotices_heading: Änderungen+ dormant: Pausiertdiff --git a/config/locales/views/bills/en.yml b/config/locales/views/bills/en.ymlindex 1a194bb99e..d2cd055848 100644--- a/config/locales/views/bills/en.yml+++ b/config/locales/views/bills/en.yml@@ -233,7 +233,8 @@ en:empty_month: No bills due this month.all:search_placeholder: Search bills- any_status: Any status+ current_bills: Current bills+ dismissed_hidden_description: Dismissed bills are hidden.status_filters:overdue: Overduedue: Due soondiff --git a/config/locales/views/bills/fr.yml b/config/locales/views/bills/fr.ymlindex 79d4e4e469..7ce151ca48 100644--- a/config/locales/views/bills/fr.yml+++ b/config/locales/views/bills/fr.yml@@ -9,7 +9,8 @@ fr:safe_to_spend: Combien puis-je dépenser sans risque cette période ?subscriptions_up: Quels abonnements ont augmenté cette année ?all:- any_status: Tous les statuts+ current_bills: Factures en cours+ dismissed_hidden_description: Les factures terminées sont masquées.any_type: Tous les typescol_actions: Actionscol_amount: Montantdiff --git a/config/locales/views/bills/pl.yml b/config/locales/views/bills/pl.ymlindex b773cd7083..a0e1148198 100644--- a/config/locales/views/bills/pl.yml+++ b/config/locales/views/bills/pl.yml@@ -9,7 +9,8 @@ pl:safe_to_spend: Ile mogę bezpiecznie wydać w tym okresie?subscriptions_up: Które subskrypcje podrożały w tym roku?all:- any_status: Dowolny status+ current_bills: Bieżące rachunki+ dismissed_hidden_description: Zakończone rachunki są ukryte.any_type: Dowolny typcol_actions: Akcjecol_amount: Kwotadiff --git a/config/locales/views/bills/ru.yml b/config/locales/views/bills/ru.ymlindex 3d58f5b766..82f4371d02 100644--- a/config/locales/views/bills/ru.yml+++ b/config/locales/views/bills/ru.yml@@ -246,7 +246,8 @@ ru:empty_month: В этом месяце нет платежей к оплате.all:search_placeholder: Поиск платежей- any_status: Любой статус+ current_bills: Текущие платежи+ dismissed_hidden_description: Завершённые платежи скрыты.status_filters:overdue: Просроченныеdue: Скоро к оплатеdiff --git a/config/locales/views/bills/tr.yml b/config/locales/views/bills/tr.ymlindex e7d20a7bfb..37207dc89a 100644--- a/config/locales/views/bills/tr.yml+++ b/config/locales/views/bills/tr.yml@@ -216,7 +216,8 @@ tr:empty_month: Bu ay vadesi gelen fatura yok.all:search_placeholder: Faturalarda ara- any_status: Tüm durumlar+ current_bills: Mevcut faturalar+ dismissed_hidden_description: Yok sayılan faturalar gizlidir.status_filters:overdue: Gecikmişdue: Vadesi yaklaşandiff --git a/config/locales/views/bills/uk.yml b/config/locales/views/bills/uk.ymlindex 4d6f0e7e3e..37f145c150 100644--- a/config/locales/views/bills/uk.yml+++ b/config/locales/views/bills/uk.yml@@ -246,7 +246,8 @@ uk:empty_month: Цього місяця платежів немає.all:search_placeholder: Шукати платежі- any_status: Будь-який статус+ current_bills: Поточні платежі+ dismissed_hidden_description: Завершені платежі приховані.status_filters:overdue: Простроченіdue: Незабаром до сплатиdiff --git a/config/locales/views/recurring_transactions/de.yml b/config/locales/views/recurring_transactions/de.ymlindex 3a4bb5b43a..f8e33ccfa1 100644--- a/config/locales/views/recurring_transactions/de.yml+++ b/config/locales/views/recurring_transactions/de.yml@@ -48,6 +48,7 @@ de:status:active: Aktivinactive: Inaktiv+ ended: Verworfenbadges:manual: Manuelltransfer_already_exists: Für dieses Kontenpaar gibt es bereits eine wiederkehrende Überweisungdiff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rbindex 914987f204..8d9816b541 100644--- a/test/controllers/bills_controller_test.rb+++ b/test/controllers/bills_controller_test.rb@@ -972,7 +972,7 @@ class BillsControllerTest < ActionDispatch::IntegrationTestendend- test "the all view lists every series and filters compose" do+ test "the all view lists every current series and filters compose" docreate_bill(name: "Alpha bill", amount: 10)create_bill(name: "Beta paused", amount: 20, status: "paused")create_bill(name: "Gamma income", amount: -500)@@ -1005,6 +1005,64 @@ class BillsControllerTest < ActionDispatch::IntegrationTestassert_no_match "Beta paused", response.bodyend+ # A removed detected bill stays as an ended tombstone so detection does not+ # recreate it. It is not a current bill, so the default list hides it and the+ # Dismissed filter is the way to find it.+ test "the all view hides dismissed bills unless the dismissed filter asks for them" do+ create_bill(name: "Live bill", amount: 10)+ create_bill(name: "Dismissed bill", amount: 20, status: "ended", manual: false)++ get bills_url(view: "all")+ assert_response :success+ assert_match "Live bill", response.body+ assert_no_match "Dismissed bill", response.body+ assert_select "select[name='q[status]'] option", text: I18n.t("bills.all.current_bills")++ get bills_url(view: "all", q: { status: "ended" })+ assert_response :success+ assert_match "Dismissed bill", response.body+ assert_no_match "Live bill", response.body+ end++ # With only tombstones left, the default list is empty. The empty state must+ # point at the filter that shows them instead of telling the user to clear a+ # filter they never set.+ test "the all view points to the dismissed filter when only dismissed bills remain" do+ create_bill(name: "Dismissed bill", amount: 20, status: "ended", manual: false)++ get bills_url(view: "all")++ assert_response :success+ assert_match I18n.t("bills.all.dismissed_hidden_description"), response.body+ assert_select "a[href=?]", bills_path(view: "all", q: { status: "ended" }),+ text: I18n.t("bills.all.status_filters.ended")+ end++ test "the all view dismissed state is localized in German" do+ @user.update!(locale: "de")+ create_bill(name: "Dismissed bill", amount: 20, status: "ended", manual: false)++ get bills_url(view: "all")++ assert_response :success+ assert_select "select[name='q[status]'] option",+ text: I18n.t("bills.all.current_bills", locale: :de, fallback: false)+ assert_match I18n.t("bills.all.no_matches_title", locale: :de, fallback: false), response.body+ assert_match I18n.t("bills.all.dismissed_hidden_description", locale: :de, fallback: false), response.body+ assert_select "a[href=?]", bills_path(view: "all", q: { status: "ended" }),+ text: I18n.t("bills.all.status_filters.ended", locale: :de, fallback: false)+ end++ test "the all view empty state is localized in German" do+ @user.update!(locale: "de")++ get bills_url(view: "all")++ assert_response :success+ assert_match I18n.t("bills.all.no_matches_title", locale: :de, fallback: false), response.body+ assert_match I18n.t("bills.all.no_matches_description", locale: :de, fallback: false), response.body+ end+# Content sits on a surface everywhere else in the app. The filters belong to# the list they filter, and the table takes the inset tray a table inside a# card gets, as the transaction list does.@@ -1676,6 +1734,52 @@ class BillsControllerTest < ActionDispatch::IntegrationTestassert_match I18n.t("bills.all.subscription_price_changes"), response.bodyend+ # The price-change list is historical, but a dismissed subscription is no+ # longer a bill. Showing its name here would put back the tombstone the list+ # just hid.+ test "the subscription price-change list skips dismissed subscriptions" do+ active = create_bill(name: "STREAMFLIX", amount: 24.99, bill_type: "subscription")+ active.recurring_price_changes.create!(+ effective_on: 2.months.ago.to_date, previous_amount: 19.99, new_amount: 24.99,+ currency: "USD", source: "detected"+ )+ dismissed = create_bill(name: "OLD STREAMFLIX", amount: 9.99, bill_type: "subscription",+ status: "ended", manual: false)+ dismissed.recurring_price_changes.create!(+ effective_on: 2.months.ago.to_date, previous_amount: 7.99, new_amount: 9.99,+ currency: "USD", source: "detected"+ )++ get bills_url(view: "all", q: { bill_type: "subscription" })++ assert_response :success+ assert_match I18n.t("bills.all.subscription_price_changes"), response.body+ assert_match "STREAMFLIX", response.body+ assert_no_match "OLD STREAMFLIX", response.body+ end++ # The subscription filter must also apply to the price-change list. Otherwise+ # a bill or installment price change appears under the subscriptions heading.+ test "the subscription price-change list skips other bill types" do+ sub = create_bill(name: "STREAMFLIX", amount: 24.99, bill_type: "subscription")+ sub.recurring_price_changes.create!(+ effective_on: 2.months.ago.to_date, previous_amount: 19.99, new_amount: 24.99,+ currency: "USD", source: "detected"+ )+ bill = create_bill(name: "CITY WATER", amount: 45, bill_type: "bill")+ bill.recurring_price_changes.create!(+ effective_on: 2.months.ago.to_date, previous_amount: 40, new_amount: 45,+ currency: "USD", source: "detected"+ )++ get bills_url(view: "all", q: { bill_type: "subscription" })++ assert_response :success+ assert_match I18n.t("bills.all.subscription_price_changes"), response.body+ assert_match "STREAMFLIX", response.body+ assert_no_match "CITY WATER", response.body+ end+# Bare, the filters read as loose words with a chevron and had no focus# ring. Each sits in the boxed field the form builder draws.test "the All bills filters are boxed fields like the search beside them" dodiff --git a/test/i18n_test.rb b/test/i18n_test.rbindex d01f102303..6692c7168a 100644--- a/test/i18n_test.rb+++ b/test/i18n_test.rb@@ -132,6 +132,17 @@ class I18nTest < ActiveSupport::TestCaseassert_empty missing, "bills.index.notices_heading is missing for: #{missing.join(", ")}"end+ # The All bills default status option. Every bills locale must translate it,+ # or the default filter falls back to English.+ def test_bills_current_bills_label_exists_for_each_bills_locale+ locales = Dir[File.expand_path("../config/locales/views/bills/*.yml", __dir__)].map { |file| File.basename(file, ".yml") }+ missing = locales.sort.reject do |locale|+ I18n.t("bills.all.current_bills", locale: locale, fallback: false, default: nil)+ end++ assert_empty missing, "bills.all.current_bills is missing for: #{missing.join(", ")}"+ end+# The family setting that fills a blank transaction name and the form# placeholder that explains it. Fallbacks would show English, so each locale# that translates the neighbouring key must translate these too.