Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Show detected bill name in the bill rules section (#4430)

joaocbatista7e2178fa11fb
diff --git a/app/helpers/bills_helper.rb b/app/helpers/bills_helper.rb
index e91960111a..e097c79b3f 100644
--- a/app/helpers/bills_helper.rb
+++ b/app/helpers/bills_helper.rb
@@ -90,7 +90,8 @@ module BillsHelper
def bills_matcher_hints(series)
{
aliases: Array(series.matcher_hints["name_aliases"]).compact_blank,
- learned_pct: series.matcher_hints["learned_tolerance_pct"].to_f
+ learned_pct: series.matcher_hints["learned_tolerance_pct"].to_f,
+ detected_name: series.merchant_id.blank? ? series.matcher_hints["detected_name"].presence : nil
}
end
diff --git a/app/views/bills/_detail.html.erb b/app/views/bills/_detail.html.erb
index 85cb5a20f0..9679e6f375 100644
--- a/app/views/bills/_detail.html.erb
+++ b/app/views/bills/_detail.html.erb
@@ -33,6 +33,11 @@
<%= t("bills.detail.rule_aliases", names: hints[:aliases].to_sentence) %>
</p>
<% end %>
+ <% if hints[:detected_name].present? && hints[:detected_name] != (series.merchant&.name.presence || series.name) %>
+ <p class="text-xs text-secondary">
+ <%= t("bills.detail.rule_detected", name: hints[:detected_name]) %>
+ </p>
+ <% end %>
<% if hints[:learned_pct].positive? %>
<p class="text-xs text-secondary">
<%= t("bills.detail.rule_learned_tolerance", percent: number_to_percentage(hints[:learned_pct], precision: 1, format: "%n%")) %>
diff --git a/config/locales/views/bills/en.yml b/config/locales/views/bills/en.yml
index 93ea9b9e56..95e9a28afa 100644
--- a/config/locales/views/bills/en.yml
+++ b/config/locales/views/bills/en.yml
@@ -42,6 +42,7 @@ en:
rule_named: "%{name}"
rule_amount_range: "from %{min} to %{max}"
rule_aliases: "Also matches %{names}"
+ rule_detected: "Matches transactions named %{name}"
rule_learned_tolerance: "Amounts within %{percent} of the usual amount match this bill"
history_title: Last 12 months
history_aria: Payments over the last twelve months
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index 83b3f3aad4..0edc6b7f5b 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -332,6 +332,20 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_no_match "var(--color-destructive)", response.body
end
+ test "the drawer names the detected bill only when it differs from the bill's name" do
+ bill = create_bill(name: "Netflix", amount: 15)
+ bill.update!(matcher_hints: { "detected_name" => "NETFLIX.COM" })
+
+ get_bill_history(bill)
+
+ assert_select "p.text-xs.text-secondary", text: I18n.t("bills.detail.rule_detected", name: "NETFLIX.COM"), count: 1
+
+ bill.update!(name: "NETFLIX.COM")
+ get_bill_history(bill)
+
+ assert_select "p.text-xs.text-secondary", text: I18n.t("bills.detail.rule_detected", name: "NETFLIX.COM"), count: 0
+ 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
diff --git a/test/helpers/bills_helper_test.rb b/test/helpers/bills_helper_test.rb
index 08d1623b7c..a96fe4a923 100644
--- a/test/helpers/bills_helper_test.rb
+++ b/test/helpers/bills_helper_test.rb
@@ -466,6 +466,24 @@ class BillsHelperTest < ActionView::TestCase
assert_equal 7.5, hints[:learned_pct]
end
+ test "matcher hints expose the detected name when one was stored" do
+ series = OpenStruct.new(matcher_hints: { "detected_name" => "NETFLIX.COM" })
+
+ assert_equal "NETFLIX.COM", bills_matcher_hints(series)[:detected_name]
+ end
+
+ test "matcher hints leave the detected name nil when none was stored" do
+ series = OpenStruct.new(matcher_hints: {})
+
+ assert_nil bills_matcher_hints(series)[:detected_name]
+ end
+
+ test "matcher hints hide the detected name for merchant-backed bills" do
+ series = OpenStruct.new(merchant_id: 1, matcher_hints: { "detected_name" => "NETFLIX.COM" })
+
+ assert_nil bills_matcher_hints(series)[:detected_name]
+ end
+
test "plan sections split the bridge from the timeline and pick the warning state" do
short_bridge = build_period(income: 0, due: 400, reserved: 0, leading: true, cash_on_hand: BigDecimal("100"))
period = build_period(income: 1200, due: 300, reserved: 100)