Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Keep detected income out of the Bills suggestion strip (#3675)

Will Wilsonbd169ff35f9d
diff --git a/app/controllers/bills_controller.rb b/app/controllers/bills_controller.rb
index e69f5c0c34..31163fe634 100644
--- a/app/controllers/bills_controller.rb
+++ b/app/controllers/bills_controller.rb
@@ -583,10 +583,13 @@ class BillsController < ApplicationController
series.where(manual: false, status: :active, id: payable_series_ids).count
end
+ # Income suggestions are reviewed in Settings -> Recurring, so detect's
+ # count leaves them out too.
def accessible_suggested_series
Current.family.recurring_transactions
.accessible_by(Current.user)
.suggested
+ .not_typed_income
end
# Family-wide, not user-scoped: occurrence materialization is the same
@@ -609,7 +612,7 @@ class BillsController < ApplicationController
.where(recurring_occurrence_id: listed.map(&:id))
# Income never reviews here: the matcher no longer suggests it, and
# this filter also retires any suggestion written before that rule.
- .merge(RecurringTransaction.where.not(bill_type: "income"))
+ .merge(RecurringTransaction.not_typed_income)
.includes(:entry, recurring_occurrence: { recurring_transaction: :merchant })
# The confidence the matcher scored these with was sitting unused on
# the row while the queue ordered itself by when the job happened to
diff --git a/app/controllers/recurring_transactions_controller.rb b/app/controllers/recurring_transactions_controller.rb
index e5e56ef6f4..4f768529aa 100644
--- a/app/controllers/recurring_transactions_controller.rb
+++ b/app/controllers/recurring_transactions_controller.rb
@@ -26,7 +26,7 @@ class RecurringTransactionsController < ApplicationController
# Fresh detections wait in their own review strip until confirmed; they
# are not real bills yet and would only be noise inside the main table.
- @suggested = scope.suggested.order(next_expected_date: :asc)
+ @suggested_income, @suggested_bills = scope.suggested.order(next_expected_date: :asc).partition(&:typed_income?)
@recurring_transactions = scope.where.not(status: :suggested)
.order(status: :asc, next_expected_date: :asc)
@family = Current.family
@@ -55,7 +55,7 @@ class RecurringTransactionsController < ApplicationController
end
end
- flash[:notice] = t("recurring_transactions.confirmed")
+ flash[:notice] = t(@recurring_transaction.typed_income? ? "recurring_transactions.confirmed_income" : "recurring_transactions.confirmed")
redirect_back_or_to recurring_transactions_path
end
diff --git a/app/views/recurring_transactions/_suggested_series.html.erb b/app/views/recurring_transactions/_suggested_series.html.erb
index 27e6c7eb43..af23b7e2d6 100644
--- a/app/views/recurring_transactions/_suggested_series.html.erb
+++ b/app/views/recurring_transactions/_suggested_series.html.erb
@@ -1,28 +1,35 @@
-<%# locals: (suggested:) %>
+<%# locals: (suggested:, income: false) %>
<%# Detection proposes, the user disposes. Rendered from both the Bills
overview and Settings -> Recurring, so every key is absolutely scoped.
Collapsible because this sits above the bills the user actually came to
see. Someone who is not ready to triage nine guesses should be able to fold
them away and still find their rent, and have that stick. %>
+<%
+ title, confirm, dismiss = if income
+ [ t("recurring_transactions.suggested_income.title"), t("recurring_transactions.suggested_income.confirm"), t("recurring_transactions.suggested_income.dismiss") ]
+ else
+ [ t("recurring_transactions.suggested.title"), t("recurring_transactions.suggested.confirm"), t("recurring_transactions.suggested.dismiss") ]
+ end
+%>
<%= render DS::Section.new(
- title: t("recurring_transactions.suggested.title"),
+ title: title,
count: suggested.size,
collapsible: true,
- persist_key: "bills-suggested"
+ persist_key: income ? "income-suggested" : "bills-suggested"
) do |section| %>
<% section.with_aside { tag.p(t("recurring_transactions.suggested.collapsed_hint"), class: "text-xs text-subdued group-open:hidden") } %>
<% suggested.each do |suggestion| %>
<%= render DS::ReviewRow.new do |row| %>
<% row.with_actions do %>
<%= render DS::Link.new(
- text: t("recurring_transactions.suggested.confirm"),
+ text: confirm,
variant: "primary",
href: confirm_recurring_transaction_path(suggestion),
method: :post
) %>
<%= render DS::Link.new(
- text: t("recurring_transactions.suggested.dismiss"),
+ text: dismiss,
variant: "ghost",
href: dismiss_recurring_transaction_path(suggestion),
method: :post
diff --git a/app/views/recurring_transactions/index.html.erb b/app/views/recurring_transactions/index.html.erb
index 4fad76c3c7..b5c376db68 100644
--- a/app/views/recurring_transactions/index.html.erb
+++ b/app/views/recurring_transactions/index.html.erb
@@ -50,8 +50,11 @@
</ul>
<% end %>
- <% if @suggested.any? %>
- <%= render "recurring_transactions/suggested_series", suggested: @suggested %>
+ <% if @suggested_bills.any? %>
+ <%= render "recurring_transactions/suggested_series", suggested: @suggested_bills %>
+ <% end %>
+ <% if @suggested_income.any? %>
+ <%= render "recurring_transactions/suggested_series", suggested: @suggested_income, income: true %>
<% end %>
<%# The Bills workspace is preview-gated, so the card that leads into it
diff --git a/config/locales/views/recurring_transactions/en.yml b/config/locales/views/recurring_transactions/en.yml
index 878f0f32ae..6f87367387 100644
--- a/config/locales/views/recurring_transactions/en.yml
+++ b/config/locales/views/recurring_transactions/en.yml
@@ -197,7 +197,12 @@ en:
collapsed_hint: Tap to review
confirm: Add bill
dismiss: Not a bill
+ suggested_income:
+ title: Possible new income
+ confirm: Add income
+ dismiss: Not income
confirmed: Bill added to your recurring transactions
+ confirmed_income: Income added to your recurring transactions
dismissed: "Dismissed. This pattern won't be suggested again."
badges:
manual: Manual
diff --git a/config/locales/views/recurring_transactions/fr.yml b/config/locales/views/recurring_transactions/fr.yml
index 45fbbc224f..23772e9cde 100644
--- a/config/locales/views/recurring_transactions/fr.yml
+++ b/config/locales/views/recurring_transactions/fr.yml
@@ -16,6 +16,7 @@ fr:
?
confirm_delete_income: Supprimer %{name} de vos revenus ? Vos transactions restent exactement telles quelles. Seuls le revenu et son échéancier sont supprimés.
confirmed: Facture ajoutée à vos transactions récurrentes
+ confirmed_income: Revenu ajouté à vos transactions récurrentes
create:
account_invalid: Choisissez un compte auquel vous pouvez ajouter des factures, ou laissez le champ vide
already_exists: Cette facture existe déjà
@@ -191,6 +192,10 @@ fr:
one: vue une fois
other: vue %{count} fois
title: Nouvelles factures possibles
+ suggested_income:
+ confirm: Ajouter le revenu
+ dismiss: Ce n'est pas un revenu
+ title: Nouveaux revenus possibles
table:
actions: Actions
amount: Montant
diff --git a/config/locales/views/recurring_transactions/pl.yml b/config/locales/views/recurring_transactions/pl.yml
index f70fce0bd7..1789d27954 100644
--- a/config/locales/views/recurring_transactions/pl.yml
+++ b/config/locales/views/recurring_transactions/pl.yml
@@ -16,6 +16,7 @@ pl:
confirm_delete_income: Usunąć %{name} jako przychód? Twoje transakcje pozostaną
bez zmian. To usuwa tylko przychód i jego harmonogram.
confirmed: Rachunek dodany do Twoich transakcji cyklicznych
+ confirmed_income: Przychód dodany do Twoich transakcji cyklicznych
create:
account_invalid: Wybierz konto, do którego możesz dodawać rachunki, albo zostaw
puste
@@ -203,6 +204,10 @@ pl:
one: widziano raz
other: widziano %{count} razy
title: Możliwe nowe rachunki
+ suggested_income:
+ confirm: Dodaj przychód
+ dismiss: To nie przychód
+ title: Możliwe nowe przychody
table:
actions: Akcje
amount: Kwota
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index 1e902602f5..98a907ced4 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -2346,6 +2346,29 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_no_match "Hidden brokerage sub", response.body
end
+ test "income suggestions stay out of the bills review strip" do
+ create_suggested(name: "Gym sub", account: accounts(:depository))
+ create_suggested(name: "ACME PAYROLL", account: accounts(:depository), amount: -2500, bill_type: "income")
+
+ get bills_url
+
+ assert_response :success
+ assert_match "Gym sub", response.body
+ assert_no_match "ACME PAYROLL", response.body
+ end
+
+ test "detect counts only bills, not income it found" do
+ 3.times do |i|
+ create_transaction_entry(name: "GYM MEMBERSHIP", amount: 40, date: Date.current - i.months)
+ create_transaction_entry(name: "ACME PAYROLL", amount: -2500, date: Date.current - i.months)
+ end
+
+ post detect_bills_url
+
+ assert @family.recurring_transactions.suggested.exists?(name: "ACME PAYROLL", bill_type: "income")
+ assert_equal I18n.t("bills.detect.found", count: 1), flash[:notice]
+ end
+
# The matcher no longer suggests income, but a suggestion written before
# that rule can still sit on the row. The queue must not render it; the
# same pending state on a bill must.
@@ -2583,13 +2606,13 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
)
end
- def create_suggested(name:, account:)
+ def create_suggested(name:, account:, amount: 15, bill_type: "bill")
@family.recurring_transactions.create!(
- name: name, account: account, amount: 15, currency: "USD",
+ name: name, account: account, amount: amount, currency: "USD",
dedup_scope: name, expected_day_of_month: 5,
last_occurrence_date: 1.month.ago.to_date,
next_expected_date: Date.current,
- status: "suggested", manual: false
+ status: "suggested", manual: false, bill_type: bill_type
)
end
diff --git a/test/controllers/recurring_transactions_controller_test.rb b/test/controllers/recurring_transactions_controller_test.rb
index d7eecae82b..76350fa191 100644
--- a/test/controllers/recurring_transactions_controller_test.rb
+++ b/test/controllers/recurring_transactions_controller_test.rb
@@ -959,6 +959,29 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTest
assert suggestion.reload.ended?
end
+ test "settings reviews detected income in its own strip, not as a possible bill" do
+ create_series(name: "CITY WATER", amount: 80, status: "suggested")
+ create_series(name: "ACME PAYROLL", amount: -2500, bill_type: "income", status: "suggested")
+
+ get recurring_transactions_url
+
+ assert_response :success
+ assert_select "[data-persisted-disclosure-key-value='bills-suggested']", text: /CITY WATER/ do |strip|
+ assert_no_match "ACME PAYROLL", strip.text
+ end
+ assert_select "[data-persisted-disclosure-key-value='income-suggested']", text: /ACME PAYROLL/ do
+ assert_select "a", text: I18n.t("recurring_transactions.suggested_income.dismiss")
+ end
+ end
+
+ test "confirming an income suggestion says income was added" do
+ suggestion = create_series(name: "ACME PAYROLL", amount: -2500, bill_type: "income", status: "suggested")
+
+ post confirm_recurring_transaction_url(suggestion)
+
+ assert_equal I18n.t("recurring_transactions.confirmed_income"), flash[:notice]
+ end
+
# --- "Search all your transactions" picker inside the add dialog ---
test "the add dialog links to the picker whether or not detection found anything" do
@@ -1257,12 +1280,14 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTest
private
- def create_series(name:, account: accounts(:depository), merchant: nil, status: "active", payment_url: nil)
+ def create_series(name:, account: accounts(:depository), merchant: nil, status: "active", payment_url: nil,
+ amount: 25, bill_type: "bill")
@family.recurring_transactions.create!(
account: account,
merchant: merchant,
name: name,
- amount: 25,
+ amount: amount,
+ bill_type: bill_type,
dedup_scope: name,
currency: "USD",
expected_day_of_month: 5,